#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 */
char *alloca(size_t);
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;
  newmode = alloca(modelen + 3);
  memcpy(newmode, mode, modelen);
  memcpy(newmode + modelen, "ce", 3);
  return fopen(file, newmode);
}


x86 assembly (clang, -O0):
<setmntent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x3,%rdi
call   1040 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rdi
add    -0x18(%rbp),%rdi
lea    0xe70(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <fopen@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setmntent>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x3(%rax),%rdi
call   1040 <alloca@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
add    %r12,%rbx
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <fopen@plt>

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*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = add i64 %9, 3
%11 = call i8* @alloca(i64 %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = trunc i64 %14 to i32
%16 = call i32 @memcpy(i8* %12, i8* %13, i32 %15)
%17 = load i8*, i8** %6
%18 = load i64, i64* %5
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = call i32 @memcpy(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%21 = load i8*, i8** %3
%22 = load i8*, i8** %6
%23 = call i32* @fopen(i8* %21, i8* %22)
ret i32* %23
}

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 = tail call i8* @alloca(i64 %4)
%6 = trunc i64 %3 to i32
%7 = tail call i32 @memcpy(i8* %5, i8* %1, i32 %6)
%8 = getelementptr inbounds i8, i8* %5, i64 %3
%9 = tail call i32 @memcpy(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%10 = tail call i32* @fopen(i8* %0, i8* %5)
ret i32* %10
}