#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ isprint(unsigned int);
int open(char const *const, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
void test_cmdline(const char *const cwd, const char *const label,
                  const char *const path) {
  int fd, n;
  char ch;
  fprintf(stderr, "%s:\n", label);
  fd = open(path, 0);
  if (fd >= 0) {
    while ((n = read(fd, &ch, 1)) > 0) {
      if (ch == '\\')
        fprintf(stderr, "\\\\");
      else if (ch == 0)
        fprintf(stderr, "\\0");
      else if (isprint((unsigned)ch))
        fprintf(stderr, "%c", ch);
      else
        fprintf(stderr, "\\0%o", ch);
    }
    fprintf(stderr, "\n");
    close(fd);
  } else
    perror("open()");
}


x86 assembly (clang, -O0):
<test_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     129c <test_cmdline+0x13c>
jmp    11ac <test_cmdline+0x4c>
mov    -0x1c(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    1278 <test_cmdline+0x118>
movsbl -0x21(%rbp),%eax
cmp    $0x5c,%eax
jne    11f2 <test_cmdline+0x92>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1273 <test_cmdline+0x113>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    121b <test_cmdline+0xbb>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    126e <test_cmdline+0x10e>
movsbl -0x21(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     124e <test_cmdline+0xee>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
movsbl -0x21(%rbp),%edx
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1269 <test_cmdline+0x109>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
movsbl -0x21(%rbp),%edx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    126e <test_cmdline+0x10e>
jmp    1273 <test_cmdline+0x113>
jmp    11ac <test_cmdline+0x4c>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
jmp    12a8 <test_cmdline+0x148>
lea    0xd70(%rip),%rdi
call   1080 <perror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cmdline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    0x2e68(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe7e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     1262 <test_cmdline+0x102>
mov    %eax,%ebx
lea    0x7(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    123c <test_cmdline+0xdc>
lea    0xe4b(%rip),%r14
lea    0x7(%rsp),%r15
lea    0xe3c(%rip),%r12
jmp    11f0 <test_cmdline+0x90>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    123c <test_cmdline+0xdc>
movsbl 0x7(%rsp),%r13d
test   %r13d,%r13d
je     11d0 <test_cmdline+0x70>
cmp    $0x5c,%r13b
jne    1210 <test_cmdline+0xb0>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
jmp    11d6 <test_cmdline+0x76>
nopl   0x0(%rax)
mov    %r13d,%edi
call   1060 <isprint@plt>
mov    0x0(%rbp),%edi
test   %rax,%rax
je     1229 <test_cmdline+0xc9>
lea    0xde4(%rip),%rsi
jmp    1230 <test_cmdline+0xd0>
lea    0xdde(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11dd <test_cmdline+0x7d>
mov    0x0(%rbp),%edi
lea    0xdbd(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <close@plt>
lea    0xdaa(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <perror@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\0\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [5 x i8] c"\\0%o\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [7 x i8] c"open()\00"
define void @test_cmdline(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %5
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %6
%14 = call i32 @open(i8* %13, i32 0)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %59
17: ; preds = %3
br label %18
18: ; preds = %53, %17
%19 = load i32, i32* %7
%20 = call i32 @read(i32 %19, i8* %9, i32 1)
store i32 %20, i32* %8
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %54
22: ; preds = %18
%23 = load i8, i8* %9
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 92
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %53
29: ; preds = %22
%30 = load i8, i8* %9
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %52
36: ; preds = %29
%37 = load i8, i8* %9
%38 = sext i8 %37 to i32
%39 = call i64 @isprint(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = load i8, i8* %9
%44 = sext i8 %43 to i32
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %51
46: ; preds = %36
%47 = load i32, i32* @stderr
%48 = load i8, i8* %9
%49 = sext i8 %48 to i32
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %46, %41
br label %52
52: ; preds = %51, %33
br label %53
53: ; preds = %52, %26
br label %18
54: ; preds = %18
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* %7
%58 = call i32 @close(i32 %57)
br label %61
59: ; preds = %3
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %59, %54
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\0\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [5 x i8] c"\\0%o\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [7 x i8] c"open()\00"
define void @test_cmdline(i8* nocapture readnone %0, i8* %1, i8* nocapture %2) {
%4 = alloca i8
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = tail call i32 @open(i8* %2, i32 0)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %36
9: ; preds = %3
%10 = call i32 @read(i32 %7, i8* %4, i32 1)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %32
12: ; preds = %9, %29
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
switch i8 %13, label %21 [
i8 92, label %15
i8 0, label %18
]
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %29
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %29
21: ; preds = %12
%22 = tail call i64 @isprint(i32 %14)
%23 = icmp eq i64 %22, 0
%24 = load i32, i32* @stderr
br i1 %23, label %27, label %25
25: ; preds = %21
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %29
27: ; preds = %21
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %29
29: ; preds = %18, %27, %25, %15
%30 = call i32 @read(i32 %7, i8* %4, i32 1)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %12, label %32
32: ; preds = %29, %9
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%35 = tail call i32 @close(i32 %7)
br label %38
36: ; preds = %3
%37 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
ret void
}