#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*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ remove(char *);
scalar_t__ strcmp(char *, char *);
char *tmpnam(int /*<<< orphan*/);
int main(void) {
  char *tmpfname = tmpnam(0);
  FILE *f = fopen(tmpfname, "w");
  if (!f) {
    perror("fopen for writing");
    return 1;
  }
  fprintf(f, "1");
  fprintf(f, "%c", '2');
  fprintf(f, "%c%c", '3', '4');
  fprintf(f, "%s", "5");
  fprintf(f, "%s%s", "6", "7");
  fprintf(f, "%i", 8);
  fprintf(f, "%.1s\n", "9x");
  fclose(f);
  f = fopen(tmpfname, "r");
  if (!f) {
    perror("fopen for reading");
    remove(tmpfname);
    return 1;
  }
  char buf[12] = "";
  if (1 != fscanf(f, "%s", buf)) {
    perror("fscanf");
    fclose(f);
    remove(tmpfname);
    return 1;
  }
  fclose(f);
  remove(tmpfname);
  if (strcmp(buf, "123456789"))
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   10c0 <tmpnam@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <main+0x51>
lea    0xe22(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x1df>
mov    -0x18(%rbp),%rdi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x32,%edx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf1(%rip),%rsi
mov    $0x33,%edx
mov    $0x34,%ecx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdde(%rip),%rsi
lea    0xdd3(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdc3(%rip),%rsi
lea    0xdc1(%rip),%rdx
lea    0xdbc(%rip),%rcx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdac(%rip),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xd98(%rip),%rsi
lea    0xd97(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12e8 <main+0x148>
lea    0xd66(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1040 <remove@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x1df>
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rdx
lea    0xd18(%rip),%rsi
call   1070 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1345 <main+0x1a5>
lea    0xd24(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <remove@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x1df>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <remove@plt>
lea    -0x24(%rbp),%rdi
lea    0xceb(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1378 <main+0x1d8>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   10c0 <tmpnam@plt>
mov    %rax,%r14
lea    0xe48(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d7 <main+0x137>
mov    %rax,%rbx
mov    $0x31,%edi
mov    %rax,%rsi
call   1070 <fputc@plt>
mov    $0x32,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
mov    $0x33,%edx
mov    $0x34,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x35,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0xe04(%rip),%rsi
lea    0xe02(%rip),%rdx
lea    0xdfd(%rip),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xdee(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xddb(%rip),%rsi
lea    0xdda(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdc4(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12ea <main+0x14a>
mov    %rax,%rbx
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xd89(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    12f8 <main+0x158>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1040 <remove@plt>
lea    0xd8e(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    131b <main+0x17b>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd24(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
jmp    12cf <main+0x12f>
lea    0xd3f(%rip),%rdi
call   10b0 <perror@plt>
jmp    130c <main+0x16c>
lea    0xd43(%rip),%rdi
call   10b0 <perror@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1040 <remove@plt>
mov    $0x1,%eax
jmp    12cf <main+0x12f>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [18 x i8] c"fopen for writing\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [5 x i8] c"%c%c\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [2 x i8] c"5\00"
@.str.7 = [5 x i8] c"%s%s\00"
@.str.8 = [2 x i8] c"6\00"
@.str.9 = [2 x i8] c"7\00"
@.str.10 = [3 x i8] c"%i\00"
@.str.11 = [6 x i8] c"%.1s\0A\00"
@.str.12 = [3 x i8] c"9x\00"
@.str.13 = [2 x i8] c"r\00"
@.str.14 = [18 x i8] c"fopen for reading\00"
@.str.15 = [7 x i8] c"fscanf\00"
@.str.16 = [10 x i8] c"123456789\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [12 x i8]
store i32 0, i32* %1
%5 = call i8* @tmpnam(i32 0)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %60
12: ; preds = %0
%13 = load i32*, i32** %3
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32*, i32** %3
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 50)
%17 = load i32*, i32** %3
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 51, i32 52)
%19 = load i32*, i32** %3
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%21 = load i32*, i32** %3
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%23 = load i32*, i32** %3
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 8)
%25 = load i32*, i32** %3
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %2
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
store i32* %30, i32** %3
%31 = load i32*, i32** %3
%32 = icmp ne i32* %31, null
br i1 %32, label %37, label %33
33: ; preds = %12
%34 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
%35 = load i8*, i8** %2
%36 = call i32 @remove(i8* %35)
store i32 1, i32* %1
br label %60
37: ; preds = %12
%38 = bitcast [12 x i8]* %4 to i8*
%39 = load i32*, i32** %3
%40 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%41 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = icmp ne i32 1, %41
br i1 %42, label %43, label %49
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%45 = load i32*, i32** %3
%46 = call i32 @fclose(i32* %45)
%47 = load i8*, i8** %2
%48 = call i32 @remove(i8* %47)
store i32 1, i32* %1
br label %60
49: ; preds = %37
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
%52 = load i8*, i8** %2
%53 = call i32 @remove(i8* %52)
%54 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0))
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %49
%58 = call i32 (...) @abort()
unreachable
59: ; preds = %49
store i32 0, i32* %1
br label %60
60: ; preds = %59, %43, %33, %10
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [18 x i8] c"fopen for writing\00"
@.str.4 = [5 x i8] c"%c%c\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.7 = [5 x i8] c"%s%s\00"
@.str.8 = [2 x i8] c"6\00"
@.str.9 = [2 x i8] c"7\00"
@.str.10 = [3 x i8] c"%i\00"
@.str.11 = [6 x i8] c"%.1s\0A\00"
@.str.12 = [3 x i8] c"9x\00"
@.str.13 = [2 x i8] c"r\00"
@.str.14 = [18 x i8] c"fopen for reading\00"
@.str.15 = [7 x i8] c"fscanf\00"
@.str.16 = [10 x i8] c"123456789\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = tail call i8* @tmpnam(i32 0)
%3 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %38
7: ; preds = %0
%8 = tail call i32 @fputc(i32 49, i32* %3)
%9 = tail call i32 @fputc(i32 50, i32* %3)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 51, i32 52)
%11 = tail call i32 @fputc(i32 53, i32* %3)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 8)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%15 = tail call i32 @fclose(i32* %3)
%16 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %7
%19 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
%20 = tail call i32 @remove(i8* %2)
br label %38
21: ; preds = %7
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%23 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%27 = call i32 @fclose(i32* %16)
%28 = call i32 @remove(i8* %2)
br label %36
29: ; preds = %21
%30 = call i32 @fclose(i32* %16)
%31 = call i32 @remove(i8* %2)
%32 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %29
%35 = call i32 (...) @abort()
unreachable
36: ; preds = %29, %25
%37 = phi i32 [ 1, %25 ], [ 0, %29 ]
br label %38
38: ; preds = %36, %18, %5
%39 = phi i32 [ %37, %36 ], [ 1, %18 ], [ 1, %5 ]
ret i32 %39
}