#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 */

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ S_IWUSR;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *);
int getpid();
scalar_t__ isdigit(int /*<<< orphan*/);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process_files(char **, int);
int /*<<< orphan*/ send_message(int /*<<< orphan*/, char *, char *);
scalar_t__ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  printf("%s (PID %d) running", argv[0], getpid());
  if (argc > 1) {
    const char *ptr = argv[1];
    while (*ptr && isdigit(*ptr++)) {
    }
    if (*ptr == '\0')
      send_message(atoi(argv[1]), argc > 2 ? argv[2] : NULL,
                   argc > 3 ? argv[3] : NULL);
    else
      process_files(argv + 1, argc - 1);
  } else {
    printf("Open and write \"test.txt\"");
    fd = open("test.txt", O_WRONLY | O_CREAT, S_IWUSR);
    if (fd == -1)
      fatal((char *)strerror(errno));
    write(fd, "Hello world\n", strlen("Hello world\n"));
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    12fe <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     1248 <main+0x88>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1258 <main+0x98>
jmp    125d <main+0x9d>
jmp    1212 <main+0x52>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12e6 <main+0x126>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1298 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    12a3 <main+0xe3>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    12a3 <main+0xe3>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    12c6 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    12d1 <main+0x111>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    12d1 <main+0x111>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%edi
mov    -0x48(%rbp),%rdx
call   1080 <send_message@plt>
jmp    12f9 <main+0x139>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   10e0 <process_files@plt>
jmp    1381 <main+0x1c1>
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%esi
mov    0x2cdc(%rip),%rax
or     (%rax),%esi
mov    0x2cbb(%rip),%rax
mov    (%rax),%edx
lea    0xd00(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1356 <main+0x196>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rdi
call   10d0 <fatal@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    0xcd4(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%edx
lea    0xcc3(%rip),%rsi
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    (%rsi),%rbp
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe22(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x2,%r15d
jl     1238 <main+0x78>
lea    0x8(%rbx),%r14
mov    0x8(%rbx),%rbp
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%rbp),%edi
test   %edi,%edi
je     12ae <main+0xee>
add    $0x1,%rbp
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1200 <main+0x40>
cmpb   $0x0,0x0(%rbp)
je     12ae <main+0xee>
add    $0xffffffff,%r15d
mov    %r14,%rdi
mov    %r15d,%esi
call   10e0 <process_files@plt>
jmp    12d7 <main+0x117>
lea    0xdd5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d73(%rip),%rax
mov    0x2da4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
lea    0xdc6(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    128a <main+0xca>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rdi
call   10d0 <fatal@plt>
lea    0xda6(%rip),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1090 <close@plt>
jmp    12d7 <main+0x117>
mov    (%r14),%rdi
call   10b0 <atoi@plt>
cmp    $0x3,%r15d
jl     12c6 <main+0x106>
mov    0x10(%rbx),%rsi
jne    12cc <main+0x10c>
xor    %edx,%edx
jmp    12d0 <main+0x110>
xor    %esi,%esi
xor    %edx,%edx
jmp    12d0 <main+0x110>
mov    0x18(%rbx),%rdx
mov    %eax,%edi
call   1080 <send_message@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%s (PID %d) running\00"
@.str.1 = [26 x i8] c"Open and write \22test.txt\22\00"
@.str.2 = [9 x i8] c"test.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@errno = global i32 0
@.str.3 = [13 x i8] c"Hello world\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11)
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %70
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %7
br label %19
19: ; preds = %33, %15
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
%29 = call i64 @isdigit(i32 %28)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %24, %19
%32 = phi i1 [ false, %19 ], [ %30, %24 ]
br i1 %32, label %33, label %34
33: ; preds = %31
br label %19
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %63
39: ; preds = %34
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = load i32, i32* %4
%45 = icmp sgt i32 %44, 2
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
br label %51
50: ; preds = %39
br label %51
51: ; preds = %50, %46
%52 = phi i8* [ %49, %46 ], [ null, %50 ]
%53 = load i32, i32* %4
%54 = icmp sgt i32 %53, 3
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
br label %60
59: ; preds = %51
br label %60
60: ; preds = %59, %55
%61 = phi i8* [ %58, %55 ], [ null, %59 ]
%62 = call i32 @send_message(i32 %43, i8* %52, i8* %61)
br label %69
63: ; preds = %34
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i32, i32* %4
%67 = sub nsw i32 %66, 1
%68 = call i32 @process_files(i8** %65, i32 %67)
br label %69
69: ; preds = %63, %60
br label %90
70: ; preds = %2
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%72 = load i32, i32* @O_WRONLY
%73 = load i32, i32* @O_CREAT
%74 = or i32 %72, %73
%75 = load i32, i32* @S_IWUSR
%76 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %74, i32 %75)
store i32 %76, i32* %6
%77 = load i32, i32* %6
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %84
79: ; preds = %70
%80 = load i32, i32* @errno
%81 = call i64 @strerror(i32 %80)
%82 = inttoptr i64 %81 to i8*
%83 = call i32 @fatal(i8* %82)
br label %84
84: ; preds = %79, %70
%85 = load i32, i32* %6
%86 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%87 = call i32 @write(i32 %85, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %86)
%88 = load i32, i32* %6
%89 = call i32 @close(i32 %88)
br label %90
90: ; preds = %84, %69
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s (PID %d) running\00"
@.str.1 = [26 x i8] c"Open and write \22test.txt\22\00"
@.str.2 = [9 x i8] c"test.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@errno = global i32 0
@.str.3 = [13 x i8] c"Hello world\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %40
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
br label %10
10: ; preds = %14, %7
%11 = phi i8* [ %9, %7 ], [ %16, %14 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %10
%15 = sext i8 %12 to i32
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = tail call i64 @isdigit(i32 %15)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %14
%20 = load i8, i8* %16
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %10, %19
%23 = load i8*, i8** %8
%24 = tail call i32 @atoi(i8* %23)
%25 = icmp sgt i32 %0, 2
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = icmp eq i32 %0, 3
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
br label %33
33: ; preds = %22, %26, %30
%34 = phi i8* [ %28, %30 ], [ %28, %26 ], [ null, %22 ]
%35 = phi i8* [ %32, %30 ], [ null, %26 ], [ null, %22 ]
%36 = tail call i32 @send_message(i32 %24, i8* %34, i8* %35)
br label %57
37: ; preds = %19
%38 = add nsw i32 %0, -1
%39 = tail call i32 @process_files(i8** %8, i32 %38)
br label %57
40: ; preds = %2
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32, i32* @O_WRONLY
%43 = load i32, i32* @O_CREAT
%44 = or i32 %43, %42
%45 = load i32, i32* @S_IWUSR
%46 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %53
48: ; preds = %40
%49 = load i32, i32* @errno
%50 = tail call i64 @strerror(i32 %49)
%51 = inttoptr i64 %50 to i8*
%52 = tail call i32 @fatal(i8* %51)
br label %53
53: ; preds = %48, %40
%54 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%55 = tail call i32 @write(i32 %46, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = tail call i32 @close(i32 %46)
br label %57
57: ; preds = %33, %37, %53
ret i32 0
}