#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  FILE *p = NULL;
  p = fopen("/tmp/test", "w+");
  char c = '1';
  char s[8];
  s[0] = c;
  fwrite(&c, 1, 1, p);
  fscanf(p, "%c", &c);
  printf("%c\n", c);
  printf("%d\n", atoi(s));
  fclose(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movb   $0x31,-0x11(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
mov    -0x10(%rbp),%rdi
lea    0xe56(%rip),%rsi
lea    -0x11(%rbp),%rdx
call   1050 <fscanf@plt>
movsbl -0x11(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
lea    -0x19(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%esi
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
movb   $0x31,0x7(%rsp)
movb   $0x31,0x8(%rsp)
mov    $0x31,%edi
mov    %rax,%rsi
call   1060 <fputc@plt>
lea    0xe74(%rip),%rsi
lea    0x7(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fscanf@plt>
movsbl 0x7(%rsp),%esi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
call   1080 <atoi@plt>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/tmp/test\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca [8 x i8]
store i32 0, i32* %1
store i32* null, i32** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
store i8 49, i8* %3
%6 = load i8, i8* %3
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
store i8 %6, i8* %7
%8 = load i32*, i32** %2
%9 = call i32 @fwrite(i8* %3, i32 1, i32 1, i32* %8)
%10 = load i32*, i32** %2
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%16 = call i32 @atoi(i8* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/tmp/test\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca [8 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8 49, i8* %1
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
store i8 49, i8* %4
%5 = tail call i32 @fputc(i32 49, i32* %3)
%6 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%7 = load i8, i8* %1
%8 = sext i8 %7 to i32
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = call i32 @atoi(i8* %4)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = call i32 @fclose(i32* %3)
ret i32 0
}