#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*/ FSETLOCKING_BYCALLER;
int /*<<< orphan*/ __fsetlocking(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mempcpy(char *, char const *, size_t);
size_t strlen(char const *);
FILE *__setmntent(const char *file, const char *mode) {
  size_t modelen = strlen(mode);
  char newmode[modelen + 3];
  memcpy(mempcpy(newmode, mode, modelen), "ce", 3);
  FILE *result = fopen(file, newmode);
  if (result != NULL)
    __fsetlocking(result, FSETLOCKING_BYCALLER);
  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),%rdx
call   1060 <mempcpy@plt>
mov    %eax,%edi
lea    0xe52(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11e6 <__setmntent+0x96>
mov    -0x30(%rbp),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
call   1050 <__fsetlocking@plt>
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   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rsp,%rbx
lea    0x12(%rax),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1060 <mempcpy@plt>
lea    0xe72(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1040 <memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11be <__setmntent+0x6e>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <__fsetlocking@plt>
mov    %rbx,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ce\00"
@FSETLOCKING_BYCALLER = global i32 0
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 = call i32 @mempcpy(i8* %14, i8* %15, i64 %16)
%18 = call i32 @memcpy(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%19 = load i8*, i8** %3
%20 = call i32* @fopen(i8* %19, i8* %14)
store i32* %20, i32** %8
%21 = load i32*, i32** %8
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %2
%24 = load i32*, i32** %8
%25 = load i32, i32* @FSETLOCKING_BYCALLER
%26 = call i32 @__fsetlocking(i32* %24, i32 %25)
br label %27
27: ; preds = %23, %2
%28 = load i32*, i32** %8
%29 = load i8*, i8** %6
ret i32* %28
}

LLVM IR (-O2):
@.str = [3 x i8] c"ce\00"
@FSETLOCKING_BYCALLER = global i32 0
define 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 = call i32 @mempcpy(i8* %5, i8* %1, i64 %3)
%7 = call i32 @memcpy(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = call i32* @fopen(i8* %0, i8* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @FSETLOCKING_BYCALLER
%12 = call i32 @__fsetlocking(i32* %8, i32 %11)
br label %13
13: ; preds = %10, %2
ret i32* %8
}