#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ xdoj_jc3_io_fprintf(char *, char *, int);
int xdoj_jc3_io_fscanf(char *, char *, int *);
int main(int argc, char **argv) {
  int val;
  (void)argc;
  if (xdoj_jc3_io_fprintf(argv[1], "%d", 20170107) < 0) {
    perror("io_fprintf");
    return 1;
  }
  if (xdoj_jc3_io_fscanf(argv[1], "%d", &val) != 1) {
    perror("io_fscanf");
    return 1;
  }
  if (val != 20170107) {
    fprintf(stderr, "expect val to be %d, but actually %d.", 20170107, val);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9b(%rip),%rsi
mov    $0x133c57b,%edx
call   1050 <xdoj_jc3_io_fprintf@plt>
cmp    $0x0,%rax
jge    1191 <main+0x51>
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1207 <main+0xc7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe60(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <xdoj_jc3_io_fscanf@plt>
cmp    $0x1,%eax
je     11ca <main+0x8a>
lea    0xe55(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1207 <main+0xc7>
cmpl   $0x133c57b,-0x14(%rbp)
je     1200 <main+0xc0>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%ecx
lea    0xe2e(%rip),%rsi
mov    $0x133c57b,%edx
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1207 <main+0xc7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xead(%rip),%rsi
mov    $0x133c57b,%edx
call   1050 <xdoj_jc3_io_fprintf@plt>
test   %rax,%rax
js     11af <main+0x6f>
mov    0x8(%rbx),%rdi
lea    0xe93(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1030 <xdoj_jc3_io_fscanf@plt>
cmp    $0x1,%eax
jne    11bd <main+0x7d>
mov    0xc(%rsp),%ecx
xor    %eax,%eax
cmp    $0x133c57b,%ecx
je     11a9 <main+0x69>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    $0x133c57b,%edx
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe4d(%rip),%rdi
call   1060 <perror@plt>
jmp    11a4 <main+0x64>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
jmp    11a4 <main+0x64>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"io_fprintf\00"
@.str.2 = [10 x i8] c"io_fscanf\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"expect val to be %d, but actually %d.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @xdoj_jc3_io_fprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 20170107)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %31
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @xdoj_jc3_io_fscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %31
23: ; preds = %15
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 20170107
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* %6
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 20170107, i32 %28)
store i32 1, i32* %3
br label %31
30: ; preds = %23
store i32 0, i32* %3
br label %31
31: ; preds = %30, %26, %21, %13
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"io_fprintf\00"
@.str.2 = [10 x i8] c"io_fscanf\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"expect val to be %d, but actually %d.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @xdoj_jc3_io_fprintf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 20170107)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %23
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @xdoj_jc3_io_fscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %23
17: ; preds = %11
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 20170107
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 20170107, i32 %18)
br label %23
23: ; preds = %17, %20, %15, %9
%24 = phi i32 [ 1, %9 ], [ 1, %15 ], [ 1, %20 ], [ 0, %17 ]
ret i32 %24
}