#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long, char *, char *);
scalar_t__ time(int /*<<< orphan*/ *);
int add_mtab(char *hostp, char *dirp) {
  FILE *mtabfile;
  if ((mtabfile = fopen("/var/db/mounttab", "a")) == NULL)
    return (0);
  else {
    fprintf(mtabfile, "%ld\t%s\t%s\n", (long)time(NULL), hostp, dirp);
    fclose(mtabfile);
    return (1);
  }
}


x86 assembly (clang, -O0):
<add_mtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117d <add_mtab+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <add_mtab+0x79>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_mtab>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeae(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1194 <add_mtab+0x54>
mov    %rax,%rbx
xor    %edi,%edi
call   1050 <time@plt>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1196 <add_mtab+0x56>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/var/db/mounttab\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [11 x i8] c"%ld\09%s\09%s\0A\00"
define i32 @add_mtab(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %6
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %18
10: ; preds = %2
%11 = load i32*, i32** %6
%12 = call i64 @time(i32* null)
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %12, i8* %13, i8* %14)
%16 = load i32*, i32** %6
%17 = call i32 @fclose(i32* %16)
store i32 1, i32* %3
br label %18
18: ; preds = %10, %9
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [17 x i8] c"/var/db/mounttab\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [11 x i8] c"%ld\09%s\09%s\0A\00"
define i32 @add_mtab(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i64 @time(i32* null)
%7 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %6, i8* %0, i8* %1)
%8 = tail call i32 @fclose(i32* %3)
br label %9
9: ; preds = %2, %5
%10 = phi i32 [ 1, %5 ], [ 0, %2 ]
ret i32 %10
}