#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ *stderr;
int main(int argc, char **argv) {
  int a, b;
  if (argc != 3)
    return 1;
  {
    char data[256];
    size_t len;
    FILE *inputfile = fopen(argv[1], "r");
    if (inputfile == NULL) {
      fprintf(stderr, "Opening file failed\n");
      return 1;
    }
    len = fread(data, 1, 256, inputfile);
    fprintf(stderr, "Read %d bytes\n", (int)len);
    fclose(inputfile);
    data[len] = '\0';
    sscanf(data, "%d %d", &a, &b);
    fprintf(stderr, "a = %d, b = %d\n", a, b);
  }
  {
    int result = a + b;
    fprintf(stderr, "result = %d\n", result);
    FILE *outputfile = fopen(argv[2], "w");
    if (outputfile == NULL) {
      fprintf(stderr, "Opening result failed\n");
      return 1;
    }
    fprintf(outputfile, "%d\n", result);
    fclose(outputfile);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     117f <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    130a <main+0x1ba>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    11cc <main+0x7c>
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130a <main+0x1ba>
lea    -0x120(%rbp),%rdi
mov    -0x130(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
mov    %rax,-0x128(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%rdi
mov    -0x128(%rbp),%rax
mov    %eax,%edx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x130(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x128(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
lea    0xdec(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1060 <sscanf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x134(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%rdi
mov    -0x134(%rbp),%edx
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdab(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x140(%rbp)
cmpq   $0x0,-0x140(%rbp)
jne    12dc <main+0x18c>
mov    0x2d21(%rip),%rax
mov    (%rax),%rdi
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130a <main+0x1ba>
mov    -0x140(%rbp),%rdi
mov    -0x134(%rbp),%edx
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x140(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    $0x1,%r12d
cmp    $0x3,%edi
jne    12a3 <main+0x143>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1271 <main+0x111>
mov    %rax,%rbx
lea    0x10(%rsp),%r15
mov    $0x1,%r12d
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,%rbp
mov    0x2e17(%rip),%r13
mov    0x0(%r13),%rdi
lea    0xe43(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movb   $0x0,0x10(%rsp,%rbp,1)
lea    0xe35(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r15,%rdi
call   1060 <sscanf@plt>
mov    0x0(%r13),%rdi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0xe16(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x8(%rsp),%ebx
add    0xc(%rsp),%ebx
mov    0x0(%r13),%rdi
lea    0xe0c(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x10(%r14),%rdi
lea    0xe05(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1289 <main+0x129>
mov    %rax,%rbp
lea    0xde0(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %r12d,%r12d
jmp    12a3 <main+0x143>
mov    0x2d68(%rip),%rax
mov    (%rax),%rcx
lea    0xd80(%rip),%rdi
mov    $0x14,%esi
jmp    1299 <main+0x139>
mov    0x0(%r13),%rcx
lea    0xdb7(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.1 = [21 x i8] c"Opening file failed\0A\00"
@.str.2 = [15 x i8] c"Read %d bytes\0A\00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [16 x i8] c"a = %d, b = %d\0A\00"
@.str.5 = [13 x i8] c"result = %d\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [23 x i8] c"Opening result failed\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 1, i32* %3
br label %65
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32*, i32** @stderr
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %65
26: ; preds = %16
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %10
%29 = call i64 @fread(i8* %27, i32 1, i32 256, i32* %28)
store i64 %29, i64* %9
%30 = load i32*, i32** @stderr
%31 = load i64, i64* %9
%32 = trunc i64 %31 to i32
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32*, i32** %10
%35 = call i32 @fclose(i32* %34)
%36 = load i64, i64* %9
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %6, i32* %7)
%40 = load i32*, i32** @stderr
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = add nsw i32 %44, %45
store i32 %46, i32* %11
%47 = load i32*, i32** @stderr
%48 = load i32, i32* %11
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %53, i32** %12
%54 = load i32*, i32** %12
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %59
56: ; preds = %26
%57 = load i32*, i32** @stderr
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %65
59: ; preds = %26
%60 = load i32*, i32** %12
%61 = load i32, i32* %11
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %12
%64 = call i32 @fclose(i32* %63)
store i32 0, i32* %3
br label %65
65: ; preds = %59, %56, %23, %15
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.1 = [21 x i8] c"Opening file failed\0A\00"
@.str.2 = [15 x i8] c"Read %d bytes\0A\00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [16 x i8] c"a = %d, b = %d\0A\00"
@.str.5 = [13 x i8] c"result = %d\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [23 x i8] c"Opening result failed\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = icmp eq i32 %0, 3
br i1 %8, label %9, label %45
9: ; preds = %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32*, i32** @stderr
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 20, i64 1, i32* %16)
br label %45
18: ; preds = %9
%19 = call i64 @fread(i8* %10, i32 1, i32 256, i32* %13)
%20 = load i32*, i32** @stderr
%21 = trunc i64 %19 to i32
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = tail call i32 @fclose(i32* %13)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %19
store i8 0, i8* %24
%25 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
%26 = load i32*, i32** @stderr
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %28)
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = add nsw i32 %31, %30
%33 = load i32*, i32** @stderr
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %18
%40 = load i32*, i32** @stderr
%41 = call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i64 22, i64 1, i32* %40)
br label %45
42: ; preds = %18
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %32)
%44 = call i32 @fclose(i32* %37)
br label %45
45: ; preds = %39, %42, %15, %2
%46 = phi i32 [ 1, %2 ], [ 1, %15 ], [ 0, %42 ], [ 1, %39 ]
ret i32 %46
}