#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 log {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ log_close(struct log *);
int /*<<< orphan*/ log_error(struct log *, int, int /*<<< orphan*/, char *,
                             int);
struct log *log_open(char *, int);
int main(int argc, char *argv[]) {
  int i;
  struct log *logfile, *logstderr;
  logfile = log_open("test.log", 7);
  for (i = 0; i <= 7; i++)
    log_error(logfile, i, 0, "hello log system: %d", i);
  logstderr = log_open(NULL, 7);
  for (i = 0; i <= 7; i++)
    log_error(logstderr, i, 0, "hello log system: %d", i);
  log_close(logfile);
  log_close(logstderr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x7,%esi
call   1030 <log_open@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x7,-0x14(%rbp)
jg     1193 <main+0x63>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%r8d
xor    %edx,%edx
lea    0xe89(%rip),%rcx
call   1040 <log_error@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1162 <main+0x32>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x7,%esi
call   1030 <log_open@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x7,-0x14(%rbp)
jg     11dd <main+0xad>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%r8d
xor    %edx,%edx
lea    0xe3f(%rip),%rcx
call   1040 <log_error@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ac <main+0x7c>
mov    -0x20(%rbp),%rdi
call   1050 <log_close@plt>
mov    -0x28(%rbp),%rdi
call   1050 <log_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rdi
mov    $0x7,%esi
call   1030 <log_open@plt>
mov    %rax,%r15
lea    0xeb9(%rip),%r14
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
mov    $0x2,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x2,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
mov    $0x3,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x3,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
mov    $0x4,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x4,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
mov    $0x5,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x5,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
mov    $0x6,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x6,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
mov    $0x7,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x7,%r8d
call   1040 <log_error@plt>
xor    %edi,%edi
mov    $0x7,%esi
call   1030 <log_open@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1040 <log_error@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
call   1040 <log_error@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x2,%r8d
call   1040 <log_error@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x3,%r8d
call   1040 <log_error@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x4,%r8d
call   1040 <log_error@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x5,%r8d
call   1040 <log_error@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x6,%r8d
call   1040 <log_error@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x7,%r8d
call   1040 <log_error@plt>
mov    %r15,%rdi
call   1050 <log_close@plt>
mov    %rbx,%rdi
call   1050 <log_close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.log = type { i32 }
@.str = [9 x i8] c"test.log\00"
@.str.1 = [21 x i8] c"hello log system: %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.log*
%8 = alloca %struct.log*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call %struct.log* @log_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 7)
store %struct.log* %9, %struct.log** %7
store i32 0, i32* %6
br label %10
10: ; preds = %18, %2
%11 = load i32, i32* %6
%12 = icmp sle i32 %11, 7
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load %struct.log*, %struct.log** %7
%15 = load i32, i32* %6
%16 = load i32, i32* %6
%17 = call i32 @log_error(%struct.log* %14, i32 %15, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %13
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %10
21: ; preds = %10
%22 = call %struct.log* @log_open(i8* null, i32 7)
store %struct.log* %22, %struct.log** %8
store i32 0, i32* %6
br label %23
23: ; preds = %31, %21
%24 = load i32, i32* %6
%25 = icmp sle i32 %24, 7
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load %struct.log*, %struct.log** %8
%28 = load i32, i32* %6
%29 = load i32, i32* %6
%30 = call i32 @log_error(%struct.log* %27, i32 %28, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %23
34: ; preds = %23
%35 = load %struct.log*, %struct.log** %7
%36 = call i32 @log_close(%struct.log* %35)
%37 = load %struct.log*, %struct.log** %8
%38 = call i32 @log_close(%struct.log* %37)
ret i32 0
}

LLVM IR (-O2):
%struct.log = type { i32 }
@.str = [9 x i8] c"test.log\00"
@.str.1 = [21 x i8] c"hello log system: %d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.log* @log_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 7)
%4 = tail call i32 @log_error(%struct.log* %3, i32 0, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 0)
%5 = tail call i32 @log_error(%struct.log* %3, i32 1, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 1)
%6 = tail call i32 @log_error(%struct.log* %3, i32 2, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 2)
%7 = tail call i32 @log_error(%struct.log* %3, i32 3, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 3)
%8 = tail call i32 @log_error(%struct.log* %3, i32 4, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 4)
%9 = tail call i32 @log_error(%struct.log* %3, i32 5, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 5)
%10 = tail call i32 @log_error(%struct.log* %3, i32 6, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 6)
%11 = tail call i32 @log_error(%struct.log* %3, i32 7, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 7)
%12 = tail call %struct.log* @log_open(i8* null, i32 7)
%13 = tail call i32 @log_error(%struct.log* %12, i32 0, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 0)
%14 = tail call i32 @log_error(%struct.log* %12, i32 1, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 1)
%15 = tail call i32 @log_error(%struct.log* %12, i32 2, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 2)
%16 = tail call i32 @log_error(%struct.log* %12, i32 3, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 3)
%17 = tail call i32 @log_error(%struct.log* %12, i32 4, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 4)
%18 = tail call i32 @log_error(%struct.log* %12, i32 5, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 5)
%19 = tail call i32 @log_error(%struct.log* %12, i32 6, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 6)
%20 = tail call i32 @log_error(%struct.log* %12, i32 7, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 7)
%21 = tail call i32 @log_close(%struct.log* %3)
%22 = tail call i32 @log_close(%struct.log* %12)
ret i32 0
}