#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
size_t strlen(char const *);
FILE *setmntent(const char *file, const char *mode) {
  size_t modelen = strlen(mode);
  char newmode[modelen + 3];
  memcpy(newmode, mode, modelen);
  memcpy(newmode + modelen, "ce", 3);
  FILE *result = fopen(file, newmode);
  return result;
}


x86 assembly (clang, -O0):
<setmntent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    %rcx,%rax
add    $0x3,%rax
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
add    $0x12,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rdi
add    -0x18(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setmntent>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %rsp,%rbx
add    $0x12,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
add    %rbx,%r12
lea    0xe8b(%rip),%rsi
mov    %r12,%rdi
mov    $0x3,%edx
call   1040 <memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fopen@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ce\00"
define i32* @setmntent(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = add i64 %11, 3
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i8*, i8** %4
%16 = load i64, i64* %5
%17 = trunc i64 %16 to i32
%18 = call i32 @memcpy(i8* %14, i8* %15, i32 %17)
%19 = load i64, i64* %5
%20 = getelementptr inbounds i8, i8* %14, i64 %19
%21 = call i32 @memcpy(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%22 = load i8*, i8** %3
%23 = call i32* @fopen(i8* %22, i8* %14)
store i32* %23, i32** %8
%24 = load i32*, i32** %8
%25 = load i8*, i8** %6
ret i32* %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"ce\00"
define noalias i32* @setmntent(i8* nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add i64 %3, 3
%5 = alloca i8, i64 %4
%6 = trunc i64 %3 to i32
%7 = call i32 @memcpy(i8* %5, i8* %1, i32 %6)
%8 = getelementptr inbounds i8, i8* %5, i64 %3
%9 = call i32 @memcpy(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%10 = call i32* @fopen(i8* %0, i8* %5)
ret i32* %10
}