#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*/ printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, ...);
int main(int argc, char **argv) {
  int i;
  char c;
  if (argc != 2) {
    return -1;
  }
  FILE *filep;
  if ((filep = fopen(argv[1], "w+")) == NULL) {
    printf("File could not be opened for write+trunc!\n");
    return -1;
  }
  while (i != 1) {
    printf("Enter type to add: ");
    scanf("%c", &c);
    if (c != 'Q') {
      putc(c, filep);
      printf("X: ");
      scanf("%i", &i);
      c = i & 0xFF;
      putc(c, filep);
      i = i & 0xFF00;
      c = i / 0x100;
      putc(c, filep);
      printf("Y: ");
      scanf("%i", &i);
      c = i & 0xFF;
      putc(c, filep);
      i = i & 0xFF00;
      c = i / 0x100;
      putc(c, filep);
      printf("Attrib: ");
      scanf("%i", &i);
      c = i & 0xFF;
      putc(c, filep);
      scanf("%c", &c);
      i = 0;
    } else {
      i = 1;
    }
  }
  fclose(filep);
  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)
cmpl   $0x2,-0x8(%rbp)
je     117c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1331 <main+0x1e1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b6 <main+0x66>
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1331 <main+0x1e1>
jmp    11bb <main+0x6b>
cmpl   $0x1,-0x14(%rbp)
je     1321 <main+0x1d1>
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
lea    -0x15(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x51,%eax
je     1315 <main+0x1c5>
mov    -0x15(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe37(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x14(%rbp),%eax
and    $0xff00,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
lea    0xdd7(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x14(%rbp),%eax
and    $0xff00,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
lea    0xd8a(%rip),%rdi
call   1040 <printf@plt>
lea    0xd77(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
lea    0xd44(%rip),%rdi
lea    -0x15(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x14(%rbp)
jmp    131c <main+0x1cc>
movl   $0x1,-0x14(%rbp)
jmp    11bb <main+0x6b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
cmp    $0x2,%edi
jne    12fd <main+0x19d>
mov    0x8(%rsi),%rdi
lea    0xe7c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12f1 <main+0x191>
mov    %rax,%rbx
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6f(%rip),%rdi
lea    0x3(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x3(%rsp),%al
cmp    $0x51,%al
je     12dd <main+0x17d>
lea    0xe57(%rip),%r12
lea    0x4(%rsp),%rbp
lea    0xe44(%rip),%r15
lea    0x3(%rsp),%r13
lea    0xe24(%rip),%r14
nop
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <putc@plt>
lea    0xe28(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movsbl 0x4(%rsp),%edi
mov    %dil,0x3(%rsp)
mov    %rbx,%rsi
call   1060 <putc@plt>
movzbl 0x5(%rsp),%eax
mov    %eax,%ecx
shl    $0x8,%ecx
mov    %ecx,0x4(%rsp)
mov    %al,0x3(%rsp)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <putc@plt>
lea    0xde7(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movsbl 0x4(%rsp),%edi
mov    %dil,0x3(%rsp)
mov    %rbx,%rsi
call   1060 <putc@plt>
movzbl 0x5(%rsp),%eax
mov    %eax,%ecx
shl    $0x8,%ecx
mov    %ecx,0x4(%rsp)
mov    %al,0x3(%rsp)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <putc@plt>
lea    0xda3(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movsbl 0x4(%rsp),%edi
mov    %dil,0x3(%rsp)
mov    %rbx,%rsi
call   1060 <putc@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movl   $0x0,0x4(%rsp)
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movzbl 0x3(%rsp),%eax
cmp    $0x51,%al
jne    11e0 <main+0x80>
movl   $0x1,0x4(%rsp)
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
jmp    12fd <main+0x19d>
lea    0xd36(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [43 x i8] c"File could not be opened for write+trunc!\0A\00"
@.str.2 = [20 x i8] c"Enter type to add: \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [4 x i8] c"X: \00"
@.str.5 = [3 x i8] c"%i\00"
@.str.6 = [4 x i8] c"Y: \00"
@.str.7 = [9 x i8] c"Attrib: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %80
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %80
20: ; preds = %12
br label %21
21: ; preds = %76, %20
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %77
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%27 = load i8, i8* %7
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 81
br i1 %29, label %30, label %75
30: ; preds = %24
%31 = load i8, i8* %7
%32 = load i32*, i32** %8
%33 = call i32 @putc(i8 signext %31, i32* %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%36 = load i32, i32* %6
%37 = and i32 %36, 255
%38 = trunc i32 %37 to i8
store i8 %38, i8* %7
%39 = load i8, i8* %7
%40 = load i32*, i32** %8
%41 = call i32 @putc(i8 signext %39, i32* %40)
%42 = load i32, i32* %6
%43 = and i32 %42, 65280
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = sdiv i32 %44, 256
%46 = trunc i32 %45 to i8
store i8 %46, i8* %7
%47 = load i8, i8* %7
%48 = load i32*, i32** %8
%49 = call i32 @putc(i8 signext %47, i32* %48)
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%51 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%52 = load i32, i32* %6
%53 = and i32 %52, 255
%54 = trunc i32 %53 to i8
store i8 %54, i8* %7
%55 = load i8, i8* %7
%56 = load i32*, i32** %8
%57 = call i32 @putc(i8 signext %55, i32* %56)
%58 = load i32, i32* %6
%59 = and i32 %58, 65280
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = sdiv i32 %60, 256
%62 = trunc i32 %61 to i8
store i8 %62, i8* %7
%63 = load i8, i8* %7
%64 = load i32*, i32** %8
%65 = call i32 @putc(i8 signext %63, i32* %64)
%66 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%67 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%68 = load i32, i32* %6
%69 = and i32 %68, 255
%70 = trunc i32 %69 to i8
store i8 %70, i8* %7
%71 = load i8, i8* %7
%72 = load i32*, i32** %8
%73 = call i32 @putc(i8 signext %71, i32* %72)
%74 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
store i32 0, i32* %6
br label %76
75: ; preds = %24
store i32 1, i32* %6
br label %76
76: ; preds = %75, %30
br label %21
77: ; preds = %21
%78 = load i32*, i32** %8
%79 = call i32 @fclose(i32* %78)
store i32 0, i32* %3
br label %80
80: ; preds = %77, %18, %11
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.2 = [20 x i8] c"Enter type to add: \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [4 x i8] c"X: \00"
@.str.5 = [3 x i8] c"%i\00"
@.str.6 = [4 x i8] c"Y: \00"
@.str.7 = [9 x i8] c"Attrib: \00"
@str = [42 x i8] c"File could not be opened for write+trunc!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %54
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%15 = load i8, i8* %4
%16 = icmp eq i8 %15, 81
br i1 %16, label %52, label %19
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %54
19: ; preds = %12, %19
%20 = phi i8 [ %50, %19 ], [ %15, %12 ]
%21 = call i32 @putc(i8 signext %20, i32* %10)
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %3
%25 = trunc i32 %24 to i8
store i8 %25, i8* %4
%26 = call i32 @putc(i8 signext %25, i32* %10)
%27 = load i32, i32* %3
%28 = and i32 %27, 65280
store i32 %28, i32* %3
%29 = lshr exact i32 %28, 8
%30 = trunc i32 %29 to i8
store i8 %30, i8* %4
%31 = call i32 @putc(i8 signext %30, i32* %10)
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%34 = load i32, i32* %3
%35 = trunc i32 %34 to i8
store i8 %35, i8* %4
%36 = call i32 @putc(i8 signext %35, i32* %10)
%37 = load i32, i32* %3
%38 = and i32 %37, 65280
store i32 %38, i32* %3
%39 = lshr exact i32 %38, 8
%40 = trunc i32 %39 to i8
store i8 %40, i8* %4
%41 = call i32 @putc(i8 signext %40, i32* %10)
%42 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%44 = load i32, i32* %3
%45 = trunc i32 %44 to i8
store i8 %45, i8* %4
%46 = call i32 @putc(i8 signext %45, i32* %10)
%47 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
store i32 0, i32* %3
%48 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%50 = load i8, i8* %4
%51 = icmp eq i8 %50, 81
br i1 %51, label %52, label %19
52: ; preds = %19, %12
store i32 1, i32* %3
%53 = call i32 @fclose(i32* %10)
br label %54
54: ; preds = %17, %52, %2
%55 = phi i32 [ -1, %2 ], [ -1, %17 ], [ 0, %52 ]
ret i32 %55
}