#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 audit_detect_machine();
char *audit_syscall_to_name(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, char const *);
int /*<<< orphan*/ perror(char *);
int main() {
  FILE *fp;
  int machine;
  const char *rsyscall;
  int i;
  fp = fopen("/etc/safed-xlate.conf", "w");
  if (!fp) {
    perror("Cannot write to safed-xlate.conf");
    return (1);
  }
  machine = audit_detect_machine();
  for (i = 0; i < 2048; i++) {
    rsyscall = audit_syscall_to_name(i, machine);
    if (rsyscall) {
      fprintf(fp, "%i:%s\n", i, rsyscall);
    }
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <main+0x49>
lea    0xe80(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    121b <main+0xbb>
mov    $0x0,%al
call   1030 <audit_detect_machine@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x800,-0x24(%rbp)
jge    120b <main+0xab>
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <audit_syscall_to_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f8 <main+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11fd <main+0x9d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ba <main+0x5a>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e0 <main+0x80>
mov    %rax,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <audit_detect_machine@plt>
mov    %eax,%ebx
lea    0xea5(%rip),%r15
jmp    11ab <main+0x4b>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x800,%ebp
je     11cb <main+0x6b>
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <audit_syscall_to_name@plt>
test   %rax,%rax
je     11a0 <main+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
call   1060 <fprintf@plt>
jmp    11a0 <main+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    11d5 <main+0x75>

LLVM IR (-O0):
@.str = [22 x i8] c"/etc/safed-xlate.conf\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [33 x i8] c"Cannot write to safed-xlate.conf\00"
@.str.3 = [7 x i8] c"%i:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %34
11: ; preds = %0
%12 = call i32 (...) @audit_detect_machine()
store i32 %12, i32* %3
store i32 0, i32* %5
br label %13
13: ; preds = %28, %11
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 2048
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = call i8* @audit_syscall_to_name(i32 %17, i32 %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i32*, i32** %2
%24 = load i32, i32* %5
%25 = load i8*, i8** %4
%26 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %25)
br label %27
27: ; preds = %22, %16
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %13
31: ; preds = %13
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %31, %9
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [22 x i8] c"/etc/safed-xlate.conf\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [33 x i8] c"Cannot write to safed-xlate.conf\00"
@.str.3 = [7 x i8] c"%i:%s\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %18
5: ; preds = %0
%6 = tail call i32 (...) @audit_detect_machine()
br label %7
7: ; preds = %5, %13
%8 = phi i32 [ 0, %5 ], [ %14, %13 ]
%9 = tail call i8* @audit_syscall_to_name(i32 %8, i32 %6)
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %8, i8* %9)
br label %13
13: ; preds = %7, %11
%14 = add nuw nsw i32 %8, 1
%15 = icmp eq i32 %14, 2048
br i1 %15, label %16, label %7
16: ; preds = %13
%17 = tail call i32 @fclose(i32* %1)
br label %18
18: ; preds = %16, %3
%19 = phi i32 [ 0, %16 ], [ 1, %3 ]
ret i32 %19
}