#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*/ daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ logData(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ mainLoop(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ perror(char *);
int setupSock(int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int sock;
  FILE *logf;
  logf = fopen("logfile.txt", "w");
  if (!logf) {
    perror("unable to open log file\n");
    exit(1);
  }
  daemon(0, 0);
  sock = setupSock(logf, 9090);
  if (sock == -1) {
    logData(logf, "failed to setup socket, exiting");
    exit(1);
  }
  logData(logf, "intial socket setup complete");
  mainLoop(logf, sock);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11be <main+0x4e>
lea    0xe5f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1050 <daemon@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2382,%esi
call   1040 <setupSock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11fc <main+0x8c>
mov    -0x20(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1030 <logData@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1030 <logData@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <mainLoop@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe86(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11a1 <main+0x31>
lea    0xe7c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
xor    %edi,%edi
xor    %esi,%esi
call   1050 <daemon@plt>
mov    %rbx,%rdi
mov    $0x2382,%esi
call   1040 <setupSock@plt>
cmp    $0xffffffff,%eax
jne    11d8 <main+0x68>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
call   1030 <logData@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %eax,%ebp
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
call   1030 <logData@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <mainLoop@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"logfile.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"unable to open log file\0A\00"
@.str.3 = [32 x i8] c"failed to setup socket, exiting\00"
@.str.4 = [29 x i8] c"intial socket setup complete\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i32 @daemon(i32 0, i32 0)
%16 = load i32*, i32** %7
%17 = call i32 @setupSock(i32* %16, i32 9090)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32*, i32** %7
%22 = call i32 @logData(i32* %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = load i32*, i32** %7
%26 = call i32 @logData(i32* %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32*, i32** %7
%28 = load i32, i32* %6
%29 = call i32 @mainLoop(i32* %27, i32 %28)
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"logfile.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"unable to open log file\0A\00"
@.str.3 = [32 x i8] c"failed to setup socket, exiting\00"
@.str.4 = [29 x i8] c"intial socket setup complete\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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 %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @daemon(i32 0, i32 0)
%10 = tail call i32 @setupSock(i32* %3, i32 9090)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @logData(i32* %3, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = tail call i32 @logData(i32* %3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%17 = tail call i32 @mainLoop(i32* %3, i32 %10)
%18 = tail call i32 @exit(i32 0)
unreachable
}