#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*/ do_test(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ log_set_desc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int args, char *argv[]) {
  FILE *log = fopen("logfifo", "w");
  if (log == NULL) {
    fprintf(stderr, "open log failed");
    return -1;
  }
  log_set_desc(log);
  do_test("cat -b -", 0);
  return 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    0xea3(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1199 <main+0x59>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <main+0x77>
mov    -0x18(%rbp),%rdi
call   1050 <log_set_desc@plt>
lea    0xe71(%rip),%rdi
xor    %esi,%esi
call   1040 <do_test@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1173 <main+0x33>
mov    %rax,%rdi
call   1050 <log_set_desc@plt>
lea    0xeb2(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1040 <do_test@plt>
jmp    118d <main+0x4d>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"logfifo\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"open log failed\00"
@.str.3 = [9 x i8] c"cat -b -\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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 = load i32*, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %17
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = call i32 @log_set_desc(i32* %14)
%16 = call i32 @do_test(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 0)
store i32 0, i32* %3
br label %17
17: ; preds = %13, %10
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@.str = [8 x i8] c"logfifo\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"open log failed\00"
@.str.3 = [9 x i8] c"cat -b -\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %11
8: ; preds = %2
%9 = tail call i32 @log_set_desc(i32* %3)
%10 = tail call i32 @do_test(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ -1, %5 ], [ 0, %8 ]
ret i32 %12
}