#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
int creat(char *, int);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main() {
  int fd = creat("hello.txt", 0644);
  if (fd > 0) {
    off_t res = lseek(fd, 100, SEEK_END);
    if (res > 0) {
      char str[100] = "Hello!";
      int written_bytes = write(fd, str, strlen(str));
      if (written_bytes > 0)
        printf("Success!!!");
    }
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x1a4,%esi
call   1090 <creat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    124a <main+0xda>
mov    -0x8(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <lseek@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    1242 <main+0xd2>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
movb   $0x48,-0x80(%rbp)
movb   $0x65,-0x7f(%rbp)
movb   $0x6c,-0x7e(%rbp)
movb   $0x6c,-0x7d(%rbp)
movb   $0x6f,-0x7c(%rbp)
movb   $0x21,-0x7b(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jle    123d <main+0xcd>
lea    0xdd2(%rip),%rdi
call   1050 <printf@plt>
jmp    1242 <main+0xd2>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xe92(%rip),%rdi
mov    $0x1a4,%esi
call   1080 <creat@plt>
test   %eax,%eax
jle    1200 <main+0xa0>
mov    %eax,%ebx
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x64,%esi
call   1060 <lseek@plt>
test   %rax,%rax
jle    11f9 <main+0x99>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x60(%rsp)
movl   $0x6c6c6548,(%rsp)
movw   $0x216f,0x4(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
jle    11f9 <main+0x99>
lea    0xe16(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"hello.txt\00"
@SEEK_END = global i32 0
@.str.1 = [11 x i8] c"Success!!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca [100 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 420)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %37
9: ; preds = %0
%10 = load i32, i32* %2
%11 = load i32, i32* @SEEK_END
%12 = call i64 @lseek(i32 %10, i32 100, i32 %11)
store i64 %12, i64* %3
%13 = load i64, i64* %3
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %34
15: ; preds = %9
%16 = bitcast [100 x i8]* %4 to i8*
%17 = bitcast i8* %16 to [100 x i8]*
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 0
store i8 72, i8* %18
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 1
store i8 101, i8* %19
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 2
store i8 108, i8* %20
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 3
store i8 108, i8* %21
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 4
store i8 111, i8* %22
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 5
store i8 33, i8* %23
%24 = load i32, i32* %2
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @write(i32 %24, i8* %25, i32 %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %15
%32 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %15
br label %34
34: ; preds = %33, %9
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
br label %37
37: ; preds = %34, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"hello.txt\00"
@SEEK_END = global i32 0
@.str.1 = [11 x i8] c"Success!!!\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 420)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %0
%5 = load i32, i32* @SEEK_END
%6 = tail call i64 @lseek(i32 %2, i32 100, i32 %5)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 72, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
store i8 101, i8* %10
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
store i8 108, i8* %11
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
store i8 108, i8* %12
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
store i8 111, i8* %13
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 5
store i8 33, i8* %14
%15 = call i32 @strlen(i8* %9)
%16 = call i32 @write(i32 %2, i8* %9, i32 %15)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %8
br label %21
21: ; preds = %20, %4
%22 = call i32 @close(i32 %2)
br label %23
23: ; preds = %21, %0
ret i32 0
}