#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *bin;
  FILE *numfile;
  char s[20] = "1234";
  int ch;
  int i;
  char line[50];
  numfile = fopen("numbers.txt", "r");
  bin = fopen("numbers.txt", "wb");
  if (numfile == NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }
  while (fgets(line, 50, numfile) != NULL) {
    i = atoi(s);
    fwrite(&i, sizeof(int), 1, bin);
  }
  getchar();
  fclose(bin);
  fclose(numfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe65(%rip),%eax
mov    %eax,-0x20(%rbp)
lea    0xe5f(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe48(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fd <main+0x7d>
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1202 <main+0x82>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1246 <main+0xc6>
lea    -0x30(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
jmp    1202 <main+0x82>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe7e(%rip),%rbx
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %r14,%r14
je     1227 <main+0xb7>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x32,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1202 <main+0x92>
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax)
movl   $0x4d2,0xc(%rsp)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %r12,%rdi
mov    $0x32,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.main.s = [20 x i8] c"1234\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"numbers.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [19 x i8] c"Cannot open file.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca [50 x i8]
store i32 0, i32* %1
%8 = bitcast [20 x i8]* %4 to i8*
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i32* @fgets(i8* %18, i32 50, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i32*, i32** %2
%26 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %25)
br label %17
27: ; preds = %17
%28 = call i32 (...) @getchar()
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"numbers.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"wb\00"
@str = [18 x i8] c"Cannot open file.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %5, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32* @fgets(i8* %4, i32 50, i32* %5)
%10 = icmp eq i32* %9, null
br i1 %10, label %18, label %14
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %14
store i32 1234, i32* %1
%15 = call i32 @fwrite(i32* %1, i32 4, i32 1, i32* %6)
%16 = call i32* @fgets(i8* %4, i32 50, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %14
18: ; preds = %14, %8
%19 = call i32 (...) @getchar()
%20 = call i32 @fclose(i32* %6)
%21 = call i32 @fclose(i32* %5)
ret i32 0
}