#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 mode_t;

/* Variables and functions */
int creat(char const *, int);
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int handle_gez(int);
int /*<<< orphan*/ printf(char *, ...);
int creat_test(const char *path, mode_t mode) {
  int fd;
  int save_errno;
  int passed;
  printf("creat(): file=%s, mode=0x%x(0%o)\n",
         (((path) == NULL) ? "(null)" : (path)), mode, mode);
  fflush(NULL);
  passed = handle_gez(fd = creat(path, mode));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tfd = %d\n", fd);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "fd = %d\n",
           fd);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return fd;
}


x86 assembly (clang, -O0):
<creat_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116a <creat_test+0x2a>
lea    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1172 <creat_test+0x32>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%ecx
lea    0xe80(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
mov    %ecx,%edx
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,%edi
call   1040 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <creat@plt>
mov    %eax,%edi
mov    %edi,-0x10(%rbp)
call   1060 <handle_gez@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xfffffffe,%eax
je     1210 <creat_test+0xd0>
jmp    11cf <creat_test+0x8f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     122f <creat_test+0xef>
jmp    11e3 <creat_test+0xa3>
mov    -0x10(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
jmp    1249 <creat_test+0x109>
mov    -0x10(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
jmp    1249 <creat_test+0x109>
mov    -0x18(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
mov    -0x14(%rbp),%ecx
mov    0x2d8d(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creat_test>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xebf(%rip),%rsi
cmovne %rdi,%rsi
lea    0xe92(%rip),%rdi
mov    %ebp,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <fflush@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <creat@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <handle_gez@plt>
mov    0x2e46(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11c3 <creat_test+0x73>
lea    0xe7d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
jmp    11e3 <creat_test+0x93>
cmp    $0xfffffffe,%eax
jne    11d3 <creat_test+0x83>
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
jmp    11dc <creat_test+0x8c>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <fflush@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"creat(): file=%s, mode=0x%x(0%o)\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"\09\09fd = %d\0A\00"
@.str.3 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.4 = [52 x i8] c"\09Failed Phase 1: returned undefined value! fd = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @creat_test(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %13
11: ; preds = %2
%12 = load i8*, i8** %3
br label %13
13: ; preds = %11, %10
%14 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %10 ], [ %12, %11 ]
%15 = load i32, i32* %4
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15, i32 %16)
%18 = call i32 @fflush(i32* null)
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = call i32 @creat(i8* %19, i32 %20)
store i32 %21, i32* %5
%22 = call i32 @handle_gez(i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* @errno
store i32 %23, i32* %6
%24 = load i32, i32* %7
switch i32 %24, label %34 [
i32 -1, label %25
i32 0, label %25
i32 -2, label %30
]
25: ; preds = %13, %13
%26 = load i32, i32* %5
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @fflush(i32* null)
br label %38
30: ; preds = %13
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = call i32 @fflush(i32* null)
br label %38
34: ; preds = %13
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = call i32 @fflush(i32* null)
br label %38
38: ; preds = %34, %30, %25
%39 = load i32, i32* %6
store i32 %39, i32* @errno
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@.str = [34 x i8] c"creat(): file=%s, mode=0x%x(0%o)\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"\09\09fd = %d\0A\00"
@.str.4 = [52 x i8] c"\09Failed Phase 1: returned undefined value! fd = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @creat_test(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %1, i32 %1)
%6 = tail call i32 @fflush(i32* null)
%7 = tail call i32 @creat(i8* %0, i32 %1)
%8 = tail call i32 @handle_gez(i32 %7)
%9 = load i32, i32* @errno
switch i32 %8, label %15 [
i32 -1, label %10
i32 0, label %10
i32 -2, label %13
]
10: ; preds = %2, %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %17
13: ; preds = %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %7)
br label %17
15: ; preds = %2
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %8)
br label %17
17: ; preds = %15, %13, %10
%18 = tail call i32 @fflush(i32* null)
store i32 %9, i32* @errno
ret i32 %7
}