#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int handle_msg(char *);
int /*<<< orphan*/ printf(char *);
int get_result(int fid) {
  printf("[DEBUG] Read Result.\n");
  FILE *ff;
  if (fid == 0)
    ff = fopen("/tmp/internet.html", "r");
  else
    ff = fopen("/tmp/web-keeplive.html", "r");
  if (ff == NULL) {
    printf("\tInternal Error. No Result was found.\n");
    return -9;
  }
  char result[512];
  fscanf(ff, "%s", result);
  fclose(ff);
  return handle_msg(result);
}


x86 assembly (clang, -O0):
<get_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %edi,-0x8(%rbp)
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1190 <get_result+0x40>
lea    0xe9b(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
jmp    11a7 <get_result+0x57>
lea    0xe94(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <get_result+0x7a>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0xfffffff7,-0x4(%rbp)
jmp    11f9 <get_result+0xa9>
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x210(%rbp),%rdi
call   1050 <handle_msg@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_result>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edi,%ebx
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
lea    0xe8f(%rip),%rax
lea    0xe9d(%rip),%rdi
cmove  %rax,%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b7 <get_result+0x67>
mov    %rax,%rbx
lea    0xe95(%rip),%rsi
mov    %rsp,%r14
mov    %rax,%rdi
mov    %r14,%rdx
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1050 <handle_msg@plt>
jmp    11c8 <get_result+0x78>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffff7,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"[DEBUG] Read Result.\0A\00"
@.str.1 = [19 x i8] c"/tmp/internet.html\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"/tmp/web-keeplive.html\00"
@.str.4 = [39 x i8] c"\09Internal Error. No Result was found.\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @get_result(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [512 x i8]
store i32 %0, i32* %3
%6 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 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* %10, i32** %4
br label %13
11: ; preds = %1
%12 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %4
br label %13
13: ; preds = %11, %9
%14 = load i32*, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
store i32 -9, i32* %2
br label %26
18: ; preds = %13
%19 = load i32*, i32** %4
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%25 = call i32 @handle_msg(i8* %24)
store i32 %25, i32* %2
br label %26
26: ; preds = %18, %16
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"/tmp/internet.html\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"/tmp/web-keeplive.html\00"
@.str.5 = [3 x i8] c"%s\00"
@str = [21 x i8] c"[DEBUG] Read Result.\00"
@str.6 = [38 x i8] c"\09Internal Error. No Result was found.\00"
define i32 @get_result(i32 %0) {
%2 = alloca [512 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %0, 0
%5 = select i1 %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0)
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.6, i64 0, i64 0))
br label %15
10: ; preds = %1
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%12 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%13 = call i32 @fclose(i32* %6)
%14 = call i32 @handle_msg(i8* %11)
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ -9, %8 ], [ %14, %10 ]
ret i32 %16
}