#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 dup(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ is_in_file(char *, char *);
int /*<<< orphan*/ log_debug(char *);
int /*<<< orphan*/ log_error(char *);
int /*<<< orphan*/ log_info(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdout;
char *tmpnam(int /*<<< orphan*/ *);
char *test_logging_output() {
  printf("Test logging: output\n");
  FILE *fp;
  char *tmp_filename;
  int stdout_bak;
  tmp_filename = tmpnam(NULL);
  stdout_bak = dup(fileno(stdout));
  fp = fopen(tmp_filename, "w");
  dup2(fileno(fp), fileno(stdout));
  log_info("Testing info");
  log_error("Testing error");
  log_debug("Testing debug");
  fflush(stdout);
  fclose(fp);
  dup2(stdout_bak, fileno(stdout));
  do {
    if (!(is_in_file(tmp_filename, "info")))
      return "Info tag not shown in log stdout";
  } while (0);
  do {
    if (!(is_in_file(tmp_filename, "error")))
      return "Error tag not shown in log stdout";
  } while (0);
  do {
    if (!(is_in_file(tmp_filename, "debug")))
      return "Debug tag not shown in log stdout";
  } while (0);
  do {
    if (!(is_in_file(tmp_filename, "Testing info")))
      return "Info log message not in stdout";
  } while (0);
  do {
    if (!(is_in_file(tmp_filename, "Testing error")))
      return "Error log message not in stdout";
  } while (0);
  do {
    if (!(is_in_file(tmp_filename, "Testing debug")))
      return "Debug log message not in stdout";
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<test_logging_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe31(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <tmpnam@plt>
mov    %rax,-0x18(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%rdi
call   10b0 <fileno@plt>
mov    %eax,%edi
call   1080 <dup@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <fileno@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%rdi
call   10b0 <fileno@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1060 <dup2@plt>
lea    0xdde(%rip),%rdi
call   1030 <log_info@plt>
lea    0xddf(%rip),%rdi
call   1050 <log_error@plt>
lea    0xde1(%rip),%rdi
call   1090 <log_debug@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%rdi
call   10c0 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%rdi
call   10b0 <fileno@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1060 <dup2@plt>
mov    -0x18(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x0,%eax
jne    12b7 <test_logging_output+0xf7>
lea    0xd93(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c3 <test_logging_output+0x203>
jmp    12bc <test_logging_output+0xfc>
jmp    12c1 <test_logging_output+0x101>
mov    -0x18(%rbp),%rdi
lea    0xd61(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x0,%eax
jne    12ea <test_logging_output+0x12a>
lea    0xd81(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c3 <test_logging_output+0x203>
jmp    12ef <test_logging_output+0x12f>
jmp    12f4 <test_logging_output+0x134>
mov    -0x18(%rbp),%rdi
lea    0xd3c(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x0,%eax
jne    131d <test_logging_output+0x15d>
lea    0xd70(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c3 <test_logging_output+0x203>
jmp    1322 <test_logging_output+0x162>
jmp    1327 <test_logging_output+0x167>
mov    -0x18(%rbp),%rdi
lea    0xce6(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x0,%eax
jne    1350 <test_logging_output+0x190>
lea    0xd5f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c3 <test_logging_output+0x203>
jmp    1355 <test_logging_output+0x195>
jmp    135a <test_logging_output+0x19a>
mov    -0x18(%rbp),%rdi
lea    0xcc0(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x0,%eax
jne    1383 <test_logging_output+0x1c3>
lea    0xd4b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c3 <test_logging_output+0x203>
jmp    1388 <test_logging_output+0x1c8>
jmp    138d <test_logging_output+0x1cd>
mov    -0x18(%rbp),%rdi
lea    0xc9b(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x0,%eax
jne    13b6 <test_logging_output+0x1f6>
lea    0xd38(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c3 <test_logging_output+0x203>
jmp    13bb <test_logging_output+0x1fb>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_logging_output>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xf20(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10e0 <tmpnam@plt>
mov    %rax,%r15
mov    0x2dfb(%rip),%r12
mov    (%r12),%rdi
call   10b0 <fileno@plt>
mov    %eax,%edi
call   1080 <dup@plt>
mov    %eax,%r14d
lea    0xe01(%rip),%rsi
mov    %r15,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10b0 <fileno@plt>
mov    %eax,%ebx
mov    (%r12),%rdi
call   10b0 <fileno@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <dup2@plt>
lea    0xdd5(%rip),%rdi
call   1040 <log_info@plt>
lea    0xdd6(%rip),%rdi
call   1060 <log_error@plt>
lea    0xdd8(%rip),%rdi
call   1090 <log_debug@plt>
mov    (%r12),%rdi
call   10c0 <fflush@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    (%r12),%rdi
call   10b0 <fileno@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1070 <dup2@plt>
lea    0xd95(%rip),%rsi
mov    %r15,%rdi
call   10a0 <is_in_file@plt>
test   %eax,%eax
je     12ef <test_logging_output+0x12f>
lea    0xd8f(%rip),%rsi
mov    %r15,%rdi
call   10a0 <is_in_file@plt>
test   %eax,%eax
je     12f8 <test_logging_output+0x138>
lea    0xd8a(%rip),%rsi
mov    %r15,%rdi
call   10a0 <is_in_file@plt>
test   %eax,%eax
je     1301 <test_logging_output+0x141>
lea    0xd54(%rip),%rsi
mov    %r15,%rdi
call   10a0 <is_in_file@plt>
test   %eax,%eax
je     130a <test_logging_output+0x14a>
lea    0xd4e(%rip),%rsi
mov    %r15,%rdi
call   10a0 <is_in_file@plt>
test   %eax,%eax
je     1313 <test_logging_output+0x153>
lea    0xd49(%rip),%rsi
mov    %r15,%rdi
call   10a0 <is_in_file@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
lea    0xde6(%rip),%rcx
cmove  %rcx,%rax
jmp    131a <test_logging_output+0x15a>
lea    0xd35(%rip),%rax
jmp    131a <test_logging_output+0x15a>
lea    0xd4d(%rip),%rax
jmp    131a <test_logging_output+0x15a>
lea    0xd66(%rip),%rax
jmp    131a <test_logging_output+0x15a>
lea    0xd7f(%rip),%rax
jmp    131a <test_logging_output+0x15a>
lea    0xd95(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Test logging: output\0A\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"Testing info\00"
@.str.3 = [14 x i8] c"Testing error\00"
@.str.4 = [14 x i8] c"Testing debug\00"
@.str.5 = [5 x i8] c"info\00"
@.str.6 = [33 x i8] c"Info tag not shown in log stdout\00"
@.str.7 = [6 x i8] c"error\00"
@.str.8 = [34 x i8] c"Error tag not shown in log stdout\00"
@.str.9 = [6 x i8] c"debug\00"
@.str.10 = [34 x i8] c"Debug tag not shown in log stdout\00"
@.str.11 = [31 x i8] c"Info log message not in stdout\00"
@.str.12 = [32 x i8] c"Error log message not in stdout\00"
@.str.13 = [32 x i8] c"Debug log message not in stdout\00"
define i8* @test_logging_output() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @tmpnam(i32* null)
store i8* %6, i8** %3
%7 = load i32*, i32** @stdout
%8 = call i32 @fileno(i32* %7)
%9 = call i32 @dup(i32 %8)
store i32 %9, i32* %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = call i32 @fileno(i32* %12)
%14 = load i32*, i32** @stdout
%15 = call i32 @fileno(i32* %14)
%16 = call i32 @dup2(i32 %13, i32 %15)
%17 = call i32 @log_info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @log_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @log_debug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32*, i32** @stdout
%21 = call i32 @fflush(i32* %20)
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %4
%25 = load i32*, i32** @stdout
%26 = call i32 @fileno(i32* %25)
%27 = call i32 @dup2(i32 %24, i32 %26)
br label %28
28: ; preds = %0
%29 = load i8*, i8** %3
%30 = call i32 @is_in_file(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %70
33: ; preds = %28
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
%36 = load i8*, i8** %3
%37 = call i32 @is_in_file(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %35
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8** %1
br label %70
40: ; preds = %35
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41
%43 = load i8*, i8** %3
%44 = call i32 @is_in_file(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %42
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8** %1
br label %70
47: ; preds = %42
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = load i8*, i8** %3
%51 = call i32 @is_in_file(i8* %50, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %49
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0), i8** %1
br label %70
54: ; preds = %49
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
%57 = load i8*, i8** %3
%58 = call i32 @is_in_file(i8* %57, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%59 = icmp ne i32 %58, 0
br i1 %59, label %61, label %60
60: ; preds = %56
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8** %1
br label %70
61: ; preds = %56
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62
%64 = load i8*, i8** %3
%65 = call i32 @is_in_file(i8* %64, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%66 = icmp ne i32 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %63
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8** %1
br label %70
68: ; preds = %63
br label %69
69: ; preds = %68
store i8* null, i8** %1
br label %70
70: ; preds = %69, %67, %60, %53, %46, %39, %32
%71 = load i8*, i8** %1
ret i8* %71
}

LLVM IR (-O2):
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"Testing info\00"
@.str.3 = [14 x i8] c"Testing error\00"
@.str.4 = [14 x i8] c"Testing debug\00"
@.str.5 = [5 x i8] c"info\00"
@.str.6 = [33 x i8] c"Info tag not shown in log stdout\00"
@.str.7 = [6 x i8] c"error\00"
@.str.8 = [34 x i8] c"Error tag not shown in log stdout\00"
@.str.9 = [6 x i8] c"debug\00"
@.str.10 = [34 x i8] c"Debug tag not shown in log stdout\00"
@.str.11 = [31 x i8] c"Info log message not in stdout\00"
@.str.12 = [32 x i8] c"Error log message not in stdout\00"
@.str.13 = [32 x i8] c"Debug log message not in stdout\00"
@str = [21 x i8] c"Test logging: output\00"
define i8* @test_logging_output() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%2 = tail call i8* @tmpnam(i32* null)
%3 = load i32*, i32** @stdout
%4 = tail call i32 @fileno(i32* %3)
%5 = tail call i32 @dup(i32 %4)
%6 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @fileno(i32* %6)
%8 = load i32*, i32** @stdout
%9 = tail call i32 @fileno(i32* %8)
%10 = tail call i32 @dup2(i32 %7, i32 %9)
%11 = tail call i32 @log_info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @log_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @log_debug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%14 = load i32*, i32** @stdout
%15 = tail call i32 @fflush(i32* %14)
%16 = tail call i32 @fclose(i32* %6)
%17 = load i32*, i32** @stdout
%18 = tail call i32 @fileno(i32* %17)
%19 = tail call i32 @dup2(i32 %5, i32 %18)
%20 = tail call i32 @is_in_file(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %38, label %22
22: ; preds = %0
%23 = tail call i32 @is_in_file(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %38, label %25
25: ; preds = %22
%26 = tail call i32 @is_in_file(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %38, label %28
28: ; preds = %25
%29 = tail call i32 @is_in_file(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %28
%32 = tail call i32 @is_in_file(i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = tail call i32 @is_in_file(i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8* null
br label %38
38: ; preds = %34, %31, %28, %25, %22, %0
%39 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), %0 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), %22 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), %25 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0), %28 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), %31 ], [ %37, %34 ]
ret i8* %39
}