#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 stat {
  int st_mode;
};

/* Variables and functions */
scalar_t__ creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct stat sb;
  int mode, nmode;
  umask(0);
  if (argc != 3) {
    fprintf(stderr, "Usage: tcreate file mode\n");
    exit(1);
  }
  mode = strtoul(argv[2], NULL, 0);
  if (creat(argv[1], mode) < 0) {
    perror("creat");
    exit(1);
  }
  if (stat(argv[1], &sb) < 0) {
    perror("stat");
    exit(1);
  }
  nmode = sb.st_mode & 0777;
  if (nmode == mode)
    fprintf(stderr, "mode %.4o\n", nmode);
  else
    fprintf(stderr, "mode %.4o != %.4o\n", nmode, mode);
  exit(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)
xor    %edi,%edi
call   1040 <umask@plt>
cmpl   $0x3,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <creat@plt>
cmp    $0x0,%rax
jge    11fe <main+0x8e>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    122f <main+0xbf>
lea    0xe00(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%eax
and    $0x1ff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1265 <main+0xf5>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1282 <main+0x112>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   1040 <umask@plt>
cmp    $0x3,%ebp
jne    11ac <main+0x3c>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
mov    %eax,%esi
call   1080 <creat@plt>
test   %rax,%rax
jns    11cd <main+0x5d>
lea    0xe70(%rip),%rdi
jmp    11e5 <main+0x75>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
jns    11f4 <main+0x84>
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x1ff,%edx
and    (%rsp),%edx
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
cmp    %ebp,%edx
jne    1220 <main+0xb0>
lea    0xe15(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe09(%rip),%rsi
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Usage: tcreate file mode\0A\00"
@.str.1 = [6 x i8] c"creat\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [11 x i8] c"mode %.4o\0A\00"
@.str.4 = [19 x i8] c"mode %.4o != %.4o\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @umask(i32 0)
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @strtoul(i8* %19, i32* null, i32 0)
store i32 %20, i32* %7
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* %7
%25 = call i64 @creat(i8* %23, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %16
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i64 @stat(i8* %33, %struct.stat* %6)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
%40 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%41 = load i32, i32* %40
%42 = and i32 %41, 511
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = load i32, i32* %8
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %55
50: ; preds = %39
%51 = load i32, i32* @stderr
%52 = load i32, i32* %8
%53 = load i32, i32* %7
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %52, i32 %53)
br label %55
55: ; preds = %50, %46
%56 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Usage: tcreate file mode\0A\00"
@.str.1 = [6 x i8] c"creat\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [11 x i8] c"mode %.4o\0A\00"
@.str.4 = [19 x i8] c"mode %.4o != %.4o\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @umask(i32 0)
%6 = icmp eq i32 %0, 3
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @strtoul(i8* nocapture %13, i32* null, i32 0)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i64 @creat(i8* %16, i32 %14)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %11
%23 = load i8*, i8** %15
%24 = call i64 @stat(i8* %23, %struct.stat* %3)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, 511
%33 = icmp eq i32 %32, %14
%34 = load i32, i32* @stderr
br i1 %33, label %35, label %37
35: ; preds = %29
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %39
37: ; preds = %29
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %14)
br label %39
39: ; preds = %37, %35
%40 = call i32 @exit(i32 0)
unreachable
}