#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 */
struct ext2_fs {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ ext2_touch_file(struct ext2_fs *, int, char *, char *, int,
                                   int);
int /*<<< orphan*/ ext2_write_file(struct ext2_fs *, int, int, char *, char *,
                                   int, int);
int /*<<< orphan*/ free(char *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(int);
int open(char *, int /*<<< orphan*/, int);
int pread(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int add_to_disk(struct ext2_fs *f, char *file_name, int i) {
  int fp_add = open(file_name, O_RDWR, 0444);
  assert(fp_add);
  int sz = lseek(fp_add, 0, SEEK_END);
  lseek(fp_add, 0, SEEK_SET);
  char *buffer = malloc(sz);
  int ret = pread(fp_add, buffer, sz, 0);
  if (i) {
    ext2_write_file(f, i, 2, file_name, buffer, 0x1C0 | 0x8000, sz);
  } else {
    ext2_touch_file(f, 2, file_name, buffer, 0x1C0, sz);
  }
  printf("%s %d\n", file_name, sz);
  free(buffer);
}


x86 assembly (clang, -O0):
<add_to_disk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    $0x124,%edx
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1070 <assert@plt>
mov    -0x20(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
xor    %ecx,%ecx
call   10a0 <pread@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1242 <add_to_disk+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x24(%rbp),%eax
mov    $0x2,%edx
mov    $0x81c0,%r9d
mov    %eax,(%rsp)
call   10b0 <ext2_write_file@plt>
jmp    1262 <add_to_disk+0xd2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x24(%rbp),%r9d
mov    $0x2,%esi
mov    $0x1c0,%r8d
call   1060 <ext2_touch_file@plt>
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xd90(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_disk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
mov    $0x124,%edx
call   1090 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <assert@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%ebp
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %ebx,%edi
mov    %rax,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   10a0 <pread@plt>
test   %r15d,%r15d
je     1227 <add_to_disk+0x97>
mov    %ebp,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    $0x2,%edx
mov    %r12,%rcx
mov    %r13,%r8
mov    $0x81c0,%r9d
call   10b0 <ext2_write_file@plt>
jmp    1243 <add_to_disk+0xb3>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %r12,%rdx
mov    %r13,%rcx
mov    $0x1c0,%r8d
mov    %ebp,%r9d
call   1060 <ext2_touch_file@plt>
lea    0xdb6(%rip),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.ext2_fs = type { i32 }
@O_RDWR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str = [7 x i8] c"%s %d\0A\00"
define i32 @add_to_disk(%struct.ext2_fs* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.ext2_fs*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store %struct.ext2_fs* %0, %struct.ext2_fs** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %6
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13, i32 292)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %8
%18 = load i32, i32* @SEEK_END
%19 = call i32 @lseek(i32 %17, i32 0, i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %8
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %20, i32 0, i32 %21)
%23 = load i32, i32* %9
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %10
%25 = load i32, i32* %8
%26 = load i8*, i8** %10
%27 = load i32, i32* %9
%28 = call i32 @pread(i32 %25, i8* %26, i32 %27, i32 0)
store i32 %28, i32* %11
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %3
%32 = load %struct.ext2_fs*, %struct.ext2_fs** %5
%33 = load i32, i32* %7
%34 = load i8*, i8** %6
%35 = load i8*, i8** %10
%36 = load i32, i32* %9
%37 = call i32 @ext2_write_file(%struct.ext2_fs* %32, i32 %33, i32 2, i8* %34, i8* %35, i32 33216, i32 %36)
br label %44
38: ; preds = %3
%39 = load %struct.ext2_fs*, %struct.ext2_fs** %5
%40 = load i8*, i8** %6
%41 = load i8*, i8** %10
%42 = load i32, i32* %9
%43 = call i32 @ext2_touch_file(%struct.ext2_fs* %39, i32 2, i8* %40, i8* %41, i32 448, i32 %42)
br label %44
44: ; preds = %38, %31
%45 = load i8*, i8** %6
%46 = load i32, i32* %9
%47 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %45, i32 %46)
%48 = load i8*, i8** %10
%49 = call i32 @free(i8* %48)
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
%struct.ext2_fs = type { i32 }
@O_RDWR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str = [7 x i8] c"%s %d\0A\00"
define i32 @add_to_disk(%struct.ext2_fs* %0, i8* %1, i32 %2) {
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* %1, i32 %4, i32 292)
%6 = tail call i32 @assert(i32 %5)
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @lseek(i32 %5, i32 0, i32 %7)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %5, i32 0, i32 %9)
%11 = tail call i8* @malloc(i32 %8)
%12 = tail call i32 @pread(i32 %5, i8* %11, i32 %8, i32 0)
%13 = icmp eq i32 %2, 0
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = tail call i32 @ext2_write_file(%struct.ext2_fs* %0, i32 %2, i32 2, i8* %1, i8* %11, i32 33216, i32 %8)
br label %18
16: ; preds = %3
%17 = tail call i32 @ext2_touch_file(%struct.ext2_fs* %0, i32 2, i8* %1, i8* %11, i32 448, i32 %8)
br label %18
18: ; preds = %16, %14
%19 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %8)
%20 = tail call i32 @free(i8* %11)
ret i32 undef
}