#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 *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(void) {
  FILE *fp;
  char str[80], strr[80];
  int x, xr;
  if ((fp = fopen("mytest", "w")) == NULL) {
    printf("Cannot open file.\n");
  }
  printf("Enter a string and a number: \n");
  fscanf(stdin, "%s %d", str, &x);
  fprintf(fp, "%s %d", str, x);
  fclose(fp);
  if ((fp = fopen("mytest", "r")) == NULL) {
    printf("Cannot open file.\n");
  }
  fscanf(fp, "%s %d", strr, &xr);
  fprintf(stdout, "%s %d\n", strr, xr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    118f <main+0x3f>
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe8b(%rip),%rsi
lea    -0xb4(%rbp),%rcx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rdx
mov    -0xb4(%rbp),%ecx
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe1a(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    120c <main+0xbc>
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
lea    0xe1d(%rip),%rsi
lea    -0xb8(%rbp),%rcx
call   1050 <fscanf@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%rdi
lea    -0xb0(%rbp),%rdx
mov    -0xb8(%rbp),%ecx
lea    0xdfb(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
lea    0xe9d(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1183 <main+0x33>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%rdi
lea    0xe69(%rip),%r14
lea    0x60(%rsp),%r15
lea    0xc(%rsp),%rcx
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe2a(%rip),%rdi
lea    0xe32(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f6 <main+0xa6>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0c(%rip),%rsi
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <fscanf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%rdi
mov    0x8(%rsp),%ecx
lea    0xdea(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"mytest\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"Cannot open file.\0A\00"
@.str.3 = [31 x i8] c"Enter a string and a number: \0A\00"
@stdin = global i32* null
@.str.4 = [6 x i8] c"%s %d\00"
@.str.5 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.6 = [7 x i8] c"%s %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32*, i32** @stdin
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%15 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %14, i32* %5)
%16 = load i32*, i32** %2
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %5
%19 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %17, i32 %18)
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
%22 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %22, i32** %2
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %11
%27 = load i32*, i32** %2
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%29 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %28, i32* %6)
%30 = load i32*, i32** @stdout
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%32 = load i32, i32* %6
%33 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %31, i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"mytest\00"
@.str.1 = [2 x i8] c"w\00"
@stdin = global i32* null
@.str.4 = [6 x i8] c"%s %d\00"
@.str.5 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.6 = [7 x i8] c"%s %d\0A\00"
@str = [30 x i8] c"Enter a string and a number: \00"
@str.8 = [18 x i8] c"Cannot open file.\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%15 = load i32*, i32** @stdin
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %5, i32* %3)
%17 = load i32, i32* %3
%18 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %5, i32 %17)
%19 = call i32 @fclose(i32* %9)
%20 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %24
24: ; preds = %22, %13
%25 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32* %4)
%26 = load i32*, i32** @stdout
%27 = load i32, i32* %4
%28 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %6, i32 %27)
ret i32 0
}