#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 */
struct mntent {
  char *mnt_opts;
  char *mnt_fsname;
  char *mnt_dir;
  char *mnt_type;
  int mnt_freq;
  int mnt_passno;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int snprintf(char *, int, char *, char *, char *, char *, char *, int, int);
scalar_t__ strlen(char *);
int addmntent(FILE *filep, const struct mntent *mnt) {
  struct mntent m = *mnt;
  char buf[2048];
  if (strlen(m.mnt_opts) == 0)
    m.mnt_opts = "rw";
  if (snprintf(buf, sizeof(buf), "%s %s %s %s %d %d\n", m.mnt_fsname, m.mnt_dir,
               m.mnt_type, m.mnt_opts, m.mnt_freq,
               m.mnt_passno) >= (int)sizeof(buf))
    return 1;
  if (fputs(buf, filep) == EOF)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<addmntent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rdi
mov    $0x28,%edx
call   1060 <memcpy@plt>
mov    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1183 <addmntent+0x43>
lea    0xe81(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x840(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x40(%rbp),%r11
mov    -0x20(%rbp),%r10d
mov    -0x1c(%rbp),%eax
mov    $0x800,%esi
lea    0xe56(%rip),%rdx
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <snprintf@plt>
cmp    $0x800,%eax
jl     11d6 <addmntent+0x96>
movl   $0x1,-0x4(%rbp)
jmp    1209 <addmntent+0xc9>
lea    -0x840(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fputs@plt>
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%rax
jne    1202 <addmntent+0xc2>
movl   $0x1,-0x4(%rbp)
jmp    1209 <addmntent+0xc9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addmntent>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
mov    (%rsi),%rax
mov    0x8(%rsi),%rcx
mov    0x10(%rsi),%r8
mov    0x18(%rsi),%r9
mov    0x20(%rsi),%r10d
cmpb   $0x0,(%rax)
mov    0x24(%rsi),%r11d
lea    0xeb2(%rip),%rbx
cmovne %rax,%rbx
sub    $0x8,%rsp
lea    0xea6(%rip),%rdx
lea    0x8(%rsp),%rdi
mov    $0x800,%esi
push   %r11
push   %r10
push   %rbx
call   1030 <snprintf@plt>
add    $0x20,%rsp
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x7ff,%ecx
jg     11a1 <addmntent+0x81>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %rax,%rcx
mov    0x2e4f(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
sete   %al
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i8*, i8*, i8*, i32, i32 }
@.str = [3 x i8] c"rw\00"
@.str.1 = [19 x i8] c"%s %s %s %s %d %d\0A\00"
@EOF = global i64 0
define i32 @addmntent(i32* %0, %struct.mntent* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.mntent*
%6 = alloca %struct.mntent
%7 = alloca [2048 x i8]
store i32* %0, i32** %4
store %struct.mntent* %1, %struct.mntent** %5
%8 = load %struct.mntent*, %struct.mntent** %5
%9 = bitcast %struct.mntent* %6 to i8*
%10 = bitcast %struct.mntent* %8 to i8*
%11 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = call i64 @strlen(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %16
br label %17
17: ; preds = %15, %2
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 2
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 3
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 4
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i32 0, i32 5
%30 = load i32, i32* %29
%31 = call i32 @snprintf(i8* %18, i32 2048, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %22, i8* %24, i8* %26, i32 %28, i32 %30)
%32 = icmp sge i32 %31, 2048
br i1 %32, label %33, label %34
33: ; preds = %17
store i32 1, i32* %3
br label %42
34: ; preds = %17
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%36 = load i32*, i32** %4
%37 = call i64 @fputs(i8* %35, i32* %36)
%38 = load i64, i64* @EOF
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 1, i32* %3
br label %42
41: ; preds = %34
store i32 0, i32* %3
br label %42
42: ; preds = %41, %40, %33
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8*, i8*, i8*, i32, i32 }
@.str = [3 x i8] c"rw\00"
@.str.1 = [19 x i8] c"%s %s %s %s %d %d\0A\00"
@EOF = global i64 0
define i32 @addmntent(i32* nocapture %0, %struct.mntent* nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 0
%5 = load i8*, i8** %4
%6 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 1
%7 = load i8*, i8** %6
%8 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 2
%9 = load i8*, i8** %8
%10 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 3
%11 = load i8*, i8** %10
%12 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 4
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 5
%15 = load i32, i32* %14
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%17 = load i8, i8* %5
%18 = icmp eq i8 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5
%20 = call i32 @snprintf(i8* %16, i32 2048, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %9, i8* %11, i8* %19, i32 %13, i32 %15)
%21 = icmp sgt i32 %20, 2047
br i1 %21, label %27, label %22
22: ; preds = %2
%23 = call i64 @fputs(i8* %16, i32* %0)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %22, %2
%28 = phi i32 [ 1, %2 ], [ %26, %22 ]
ret i32 %28
}