#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ hook_stdout(char *);
int /*<<< orphan*/ print_mng_addr(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ unhook_stdout();
int test_mgmt_printing() {
  char *mgmt_info_test;
  int result = 1;
  FILE *output;
  int ctr = 0;
  mgmt_info_test = "05010a2ff8f9"
                   "0100000000"
                   "0c0103060102011f0101010100";
  hook_stdout("test_mgmt_printing.txt");
  print_mng_addr(strlen(mgmt_info_test), mgmt_info_test);
  fflush(stdout);
  output = fopen("test_mgmt_printing.txt", "r");
  if (!output)
    goto done;
  while (!feof(output) && ctr != 3) {
    char buf[1024];
    if (!fgets(buf, sizeof(buf), output))
      goto done;
    if (!strcmp(buf, "IPv4: 10.47.248.249\n"))
      ctr++;
    else if (!strcmp(buf, "\tUnknown interface subtype: 0\n"))
      ctr++;
    else if (!strcmp(buf, "\tOID: 0.1.3.6.1.2.1.31.1.1.1.1.0\n"))
      ctr++;
    else {
      fprintf(stderr, "FATAL: unknown line '%s'\n", buf);
      goto done;
    }
  }
  result = 0;
done:
  if (output)
    fclose(output);
  unhook_stdout();
  return result;
}


x86 assembly (clang, -O0):
<test_mgmt_printing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe56(%rip),%rdi
call   1030 <hook_stdout@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
call   10c0 <print_mng_addr@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0xe28(%rip),%rdi
lea    0xe38(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1229 <test_mgmt_printing+0x79>
jmp    1342 <test_mgmt_printing+0x192>
jmp    122e <test_mgmt_printing+0x7e>
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x421(%rbp)
jne    1257 <test_mgmt_printing+0xa7>
cmpl   $0x3,-0x1c(%rbp)
setne  %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    126a <test_mgmt_printing+0xba>
jmp    133b <test_mgmt_printing+0x18b>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    128d <test_mgmt_printing+0xdd>
jmp    1342 <test_mgmt_printing+0x192>
lea    -0x420(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12b7 <test_mgmt_printing+0x107>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1336 <test_mgmt_printing+0x186>
lea    -0x420(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12e1 <test_mgmt_printing+0x131>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1331 <test_mgmt_printing+0x181>
lea    -0x420(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    130b <test_mgmt_printing+0x15b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    132c <test_mgmt_printing+0x17c>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xd7e(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1342 <test_mgmt_printing+0x192>
jmp    1331 <test_mgmt_printing+0x181>
jmp    1336 <test_mgmt_printing+0x186>
jmp    122e <test_mgmt_printing+0x7e>
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1356 <test_mgmt_printing+0x1a6>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   10a0 <unhook_stdout@plt>
mov    -0xc(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mgmt_printing>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xeab(%rip),%rbx
mov    %rbx,%rdi
call   1030 <hook_stdout@plt>
lea    0xe6b(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   10c0 <print_mng_addr@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12dc <test_mgmt_printing+0x12c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    1302 <test_mgmt_printing+0x152>
mov    $0x2,%ebp
mov    %rsp,%r12
lea    0xe8c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     12fc <test_mgmt_printing+0x14c>
movdqu 0x5(%rsp),%xmm0
pcmpeqb 0xd9a(%rip),%xmm0
movdqa (%rsp),%xmm1
pcmpeqb 0xd9d(%rip),%xmm1
pand   %xmm0,%xmm1
pmovmskb %xmm1,%eax
cmp    $0xffff,%eax
je     12c0 <test_mgmt_printing+0x110>
movdqu 0xf(%rsp),%xmm0
pcmpeqb 0xd90(%rip),%xmm0
movdqa (%rsp),%xmm1
pcmpeqb 0xd93(%rip),%xmm1
pand   %xmm0,%xmm1
pmovmskb %xmm1,%eax
cmp    $0xffff,%eax
je     12c0 <test_mgmt_printing+0x110>
mov    $0x22,%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   10b0 <bcmp@plt>
test   %eax,%eax
jne    12e4 <test_mgmt_printing+0x134>
mov    %rbx,%rdi
call   1080 <feof@plt>
add    $0xffffffff,%ebp
setb   %cl
test   %eax,%eax
jne    1302 <test_mgmt_printing+0x152>
test   %cl,%cl
jne    1240 <test_mgmt_printing+0x90>
jmp    1302 <test_mgmt_printing+0x152>
mov    $0x1,%r14d
jmp    130a <test_mgmt_printing+0x15a>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    %rsp,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1090 <unhook_stdout@plt>
mov    %r14d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"05010a2ff8f901000000000c0103060102011f0101010100\00"
@.str.1 = [23 x i8] c"test_mgmt_printing.txt\00"
@stdout = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"IPv4: 10.47.248.249\0A\00"
@.str.4 = [31 x i8] c"\09Unknown interface subtype: 0\0A\00"
@.str.5 = [34 x i8] c"\09OID: 0.1.3.6.1.2.1.31.1.1.1.1.0\0A\00"
@stderr = global i32 0
@.str.6 = [26 x i8] c"FATAL: unknown line '%s'\0A\00"
define i32 @test_mgmt_printing() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 1, i32* %2
store i32 0, i32* %4
store i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8** %1
%6 = call i32 @hook_stdout(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%7 = load i8*, i8** %1
%8 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %1
%10 = call i32 @print_mng_addr(i32 %8, i8* %9)
%11 = load i32, i32* @stdout
%12 = call i32 @fflush(i32 %11)
%13 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %0
br label %62
17: ; preds = %0
br label %18
18: ; preds = %60, %17
%19 = load i32*, i32** %3
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 3
br label %25
25: ; preds = %22, %18
%26 = phi i1 [ false, %18 ], [ %24, %22 ]
br i1 %26, label %27, label %61
27: ; preds = %25
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = load i32*, i32** %3
%30 = call i32 @fgets(i8* %28, i32 1024, i32* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
br label %62
33: ; preds = %27
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %60
40: ; preds = %33
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %59
47: ; preds = %40
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%49 = call i32 @strcmp(i8* %48, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %58
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%57 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %56)
br label %62
58: ; preds = %51
br label %59
59: ; preds = %58, %44
br label %60
60: ; preds = %59, %37
br label %18
61: ; preds = %25
store i32 0, i32* %2
br label %62
62: ; preds = %61, %54, %32, %16
%63 = load i32*, i32** %3
%64 = icmp ne i32* %63, null
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32*, i32** %3
%67 = call i32 @fclose(i32* %66)
br label %68
68: ; preds = %65, %62
%69 = call i32 (...) @unhook_stdout()
%70 = load i32, i32* %2
ret i32 %70
}

LLVM IR (-O2):
@.str = [49 x i8] c"05010a2ff8f901000000000c0103060102011f0101010100\00"
@.str.1 = [23 x i8] c"test_mgmt_printing.txt\00"
@stdout = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"IPv4: 10.47.248.249\0A\00"
@.str.4 = [31 x i8] c"\09Unknown interface subtype: 0\0A\00"
@.str.5 = [34 x i8] c"\09OID: 0.1.3.6.1.2.1.31.1.1.1.1.0\0A\00"
@stderr = global i32 0
@.str.6 = [26 x i8] c"FATAL: unknown line '%s'\0A\00"
define i32 @test_mgmt_printing() {
%1 = alloca [1024 x i8]
%2 = tail call i32 @hook_stdout(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @print_mng_addr(i32 %3, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %40, label %9
9: ; preds = %0
%10 = call i32 @feof(i32* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %9
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %14
14: ; preds = %12, %31
%15 = phi i32 [ 0, %12 ], [ %32, %31 ]
%16 = call i32 @fgets(i8* %13, i32 1024, i32* %7)
%17 = icmp eq i32 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %14
%19 = call i32 @bcmp(i8* dereferenceable(21) %13, i8* dereferenceable(21) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 21)
%20 = icmp eq i32 %19, 0
br i1 %20, label %31, label %21
21: ; preds = %18
%22 = call i32 @bcmp(i8* dereferenceable(31) %13, i8* dereferenceable(31) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 31)
%23 = icmp eq i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = call i32 @bcmp(i8* dereferenceable(34) %13, i8* dereferenceable(34) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i64 34)
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %13)
br label %30
30: ; preds = %14, %27
br label %37
31: ; preds = %18, %21, %24
%32 = add nuw nsw i32 %15, 1
%33 = call i32 @feof(i32* %7)
%34 = icmp eq i32 %33, 0
%35 = icmp ne i32 %32, 3
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %14, label %37
37: ; preds = %31, %30, %9
%38 = phi i32 [ 1, %30 ], [ 0, %9 ], [ 0, %31 ]
%39 = call i32 @fclose(i32* %7)
br label %40
40: ; preds = %0, %37
%41 = phi i32 [ %38, %37 ], [ 1, %0 ]
%42 = call i32 (...) @unhook_stdout()
ret i32 %41
}