#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*/ PATH_MAX;
int cpio_mkfile(char *, char *, unsigned int, int, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ isgraph(char const);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int sscanf(char const *, char *, char *, ...);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int cpio_mkfile_line(const char *line) {
  char name[PATH_MAX + 1];
  char *dname = NULL;
  char location[PATH_MAX + 1];
  unsigned int mode;
  int uid;
  int gid;
  int nlinks = 1;
  int end = 0, dname_len = 0;
  int rc = -1;
  if (5 > sscanf(line,
                 "%"
                 "PATH_MAX"
                 "s %"
                 "PATH_MAX"
                 "s %o %d %d %n",
                 name, location, &mode, &uid, &gid, &end)) {
    fprintf(stderr, "Unrecognized file format '%s'", line);
    goto fail;
  }
  if (end && isgraph(line[end])) {
    int len;
    int nend;
    dname = malloc(strlen(line));
    if (!dname) {
      fprintf(stderr, "out of memory (%d)\n", dname_len);
      goto fail;
    }
    dname_len = strlen(name) + 1;
    memcpy(dname, name, dname_len);
    do {
      nend = 0;
      if (sscanf(line + end,
                 "%"
                 "PATH_MAX"
                 "s %n",
                 name, &nend) < 1)
        break;
      len = strlen(name) + 1;
      memcpy(dname + dname_len, name, len);
      dname_len += len;
      nlinks++;
      end += nend;
    } while (isgraph(line[end]));
  } else {
    dname = name;
  }
  rc = cpio_mkfile(dname, location, mode, uid, gid, nlinks);
fail:
  if (dname_len)
    free(dname);
  return rc;
}


x86 assembly (clang, -O0):
<cpio_mkfile_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdf5(%rip),%rsi
lea    -0x2c(%rbp),%r8
lea    -0x30(%rbp),%r9
lea    -0x34(%rbp),%r10
lea    -0x3c(%rbp),%rax
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1080 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,%ecx
mov    $0x5,%eax
cmp    %ecx,%eax
jle    1262 <cpio_mkfile_line+0xe2>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13a1 <cpio_mkfile_line+0x221>
cmpl   $0x0,-0x3c(%rbp)
je     137b <cpio_mkfile_line+0x1fb>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   10a0 <isgraph@plt>
cmp    $0x0,%rax
je     137b <cpio_mkfile_line+0x1fb>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12c5 <cpio_mkfile_line+0x145>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%edx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13a1 <cpio_mkfile_line+0x221>
mov    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rsi
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x60(%rbp),%rdx
movl   $0x0,-0x4c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
lea    0xd53(%rip),%rsi
lea    -0x4c(%rbp),%rcx
mov    $0x0,%al
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jge    131a <cpio_mkfile_line+0x19a>
jmp    1376 <cpio_mkfile_line+0x1f6>
mov    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rsi
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x40(%rbp),%rax
add    %rax,%rdi
mov    -0x48(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x48(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x4c(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   10a0 <isgraph@plt>
cmp    $0x0,%rax
jne    12e4 <cpio_mkfile_line+0x164>
jmp    1383 <cpio_mkfile_line+0x203>
mov    -0x60(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x58(%rbp),%rsi
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
call   1090 <cpio_mkfile@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     13b4 <cpio_mkfile_line+0x234>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpio_mkfile_line>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r12
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
movl   $0x0,-0x2c(%rbp)
lea    -0x2c(%rbp),%r10
lea    -0x38(%rbp),%r11
lea    0xe30(%rip),%rsi
xor    %r13d,%r13d
lea    -0x40(%rbp),%r8
lea    -0x3c(%rbp),%r9
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
push   %r10
push   %r11
call   1080 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x4,%eax
jg     1219 <cpio_mkfile_line+0x99>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1343 <cpio_mkfile_line+0x1c3>
movslq -0x2c(%rbp),%rax
mov    $0x1,%r15d
test   %rax,%rax
je     1319 <cpio_mkfile_line+0x199>
movsbl (%r12,%rax,1),%edi
call   10a0 <isgraph@plt>
test   %rax,%rax
je     1319 <cpio_mkfile_line+0x199>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1354 <cpio_mkfile_line+0x1d4>
mov    %rax,%r15
mov    %r14,-0x50(%rbp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %r15,-0x48(%rbp)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,-0x30(%rbp)
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x0,-0x34(%rbp)
movslq -0x2c(%rbp),%rdi
add    %r12,%rdi
lea    0xdaf(%rip),%rsi
mov    %rbx,%rdx
lea    -0x34(%rbp),%rcx
xor    %eax,%eax
call   1080 <sscanf@plt>
test   %eax,%eax
jle    130b <cpio_mkfile_line+0x18b>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%r13
mov    %eax,%r14d
lea    0x1(%r14),%edx
movslq -0x30(%rbp),%rbx
mov    -0x48(%rbp),%rax
lea    (%rax,%rbx,1),%rdi
mov    %r13,%rsi
call   1060 <memcpy@plt>
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    %r13,%rbx
add    $0x1,%r15d
movslq -0x34(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rax,%rcx
mov    %ecx,-0x2c(%rbp)
movsbl (%r12,%rcx,1),%edi
call   10a0 <isgraph@plt>
test   %rax,%rax
jne    1290 <cpio_mkfile_line+0x110>
mov    -0x50(%rbp),%r14
mov    -0x30(%rbp),%r13d
mov    -0x48(%rbp),%r12
jmp    131c <cpio_mkfile_line+0x19c>
mov    %rbx,%r12
mov    -0x40(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%r9d
call   1090 <cpio_mkfile@plt>
mov    %eax,%ebx
test   %r13d,%r13d
je     1343 <cpio_mkfile_line+0x1c3>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    120f <cpio_mkfile_line+0x8f>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [34 x i8] c"%PATH_MAXs %PATH_MAXs %o %d %d %n\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Unrecognized file format '%s'\00"
@.str.2 = [20 x i8] c"out of memory (%d)\0A\00"
@.str.3 = [14 x i8] c"%PATH_MAXs %n\00"
define i32 @cpio_mkfile_line(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %2
%16 = load i32, i32* @PATH_MAX
%17 = add nsw i32 %16, 1
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %3
%20 = alloca i8, i64 %18
store i64 %18, i64* %4
store i8* null, i8** %5
%21 = load i32, i32* @PATH_MAX
%22 = add nsw i32 %21, 1
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
store i64 %23, i64* %6
store i32 1, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 -1, i32* %13
%25 = load i8*, i8** %2
%26 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %24, i32* %7, i32* %8, i32* %9, i32* %11)
%27 = icmp sgt i32 5, %26
br i1 %27, label %28, label %32
28: ; preds = %1
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %2
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %101
32: ; preds = %1
%33 = load i32, i32* %11
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %93
35: ; preds = %32
%36 = load i8*, i8** %2
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = call i64 @isgraph(i8 signext %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %93
43: ; preds = %35
%44 = load i8*, i8** %2
%45 = call i32 @strlen(i8* %44)
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %5
%47 = load i8*, i8** %5
%48 = icmp ne i8* %47, null
br i1 %48, label %53, label %49
49: ; preds = %43
%50 = load i32, i32* @stderr
%51 = load i32, i32* %12
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %101
53: ; preds = %43
%54 = call i32 @strlen(i8* %20)
%55 = add nsw i32 %54, 1
store i32 %55, i32* %12
%56 = load i8*, i8** %5
%57 = load i32, i32* %12
%58 = call i32 @memcpy(i8* %56, i8* %20, i32 %57)
br label %59
59: ; preds = %84, %53
store i32 0, i32* %15
%60 = load i8*, i8** %2
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %63, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %20, i32* %15)
%65 = icmp slt i32 %64, 1
br i1 %65, label %66, label %67
66: ; preds = %59
br label %92
67: ; preds = %59
%68 = call i32 @strlen(i8* %20)
%69 = add nsw i32 %68, 1
store i32 %69, i32* %14
%70 = load i8*, i8** %5
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = load i32, i32* %14
%75 = call i32 @memcpy(i8* %73, i8* %20, i32 %74)
%76 = load i32, i32* %14
%77 = load i32, i32* %12
%78 = add nsw i32 %77, %76
store i32 %78, i32* %12
%79 = load i32, i32* %10
%80 = add nsw i32 %79, 1
store i32 %80, i32* %10
%81 = load i32, i32* %15
%82 = load i32, i32* %11
%83 = add nsw i32 %82, %81
store i32 %83, i32* %11
br label %84
84: ; preds = %67
%85 = load i8*, i8** %2
%86 = load i32, i32* %11
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = load i8, i8* %88
%90 = call i64 @isgraph(i8 signext %89)
%91 = icmp ne i64 %90, 0
br i1 %91, label %59, label %92
92: ; preds = %84, %66
br label %94
93: ; preds = %35, %32
store i8* %20, i8** %5
br label %94
94: ; preds = %93, %92
%95 = load i8*, i8** %5
%96 = load i32, i32* %7
%97 = load i32, i32* %8
%98 = load i32, i32* %9
%99 = load i32, i32* %10
%100 = call i32 @cpio_mkfile(i8* %95, i8* %24, i32 %96, i32 %97, i32 %98, i32 %99)
store i32 %100, i32* %13
br label %101
101: ; preds = %94, %49, %28
%102 = load i32, i32* %12
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %101
%105 = load i8*, i8** %5
%106 = call i32 @free(i8* %105)
br label %107
107: ; preds = %104, %101
%108 = load i32, i32* %13
%109 = load i8*, i8** %3
ret i32 %108
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [34 x i8] c"%PATH_MAXs %PATH_MAXs %o %d %d %n\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Unrecognized file format '%s'\00"
@.str.2 = [20 x i8] c"out of memory (%d)\0A\00"
@.str.3 = [14 x i8] c"%PATH_MAXs %n\00"
define i32 @cpio_mkfile_line(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @PATH_MAX
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = alloca i8, i64 %9
%12 = bitcast i32* %2 to i8*
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
%15 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%16 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11, i32* %2, i32* %3, i32* %4, i32* %5)
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %80
21: ; preds = %1
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 0
br i1 %23, label %69, label %24
24: ; preds = %21
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @isgraph(i8 signext %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %69, label %30
30: ; preds = %24
%31 = bitcast i32* %6 to i8*
%32 = call i32 @strlen(i8* %0)
%33 = call i8* @malloc(i32 %32)
%34 = icmp eq i8* %33, null
br i1 %34, label %66, label %35
35: ; preds = %30
%36 = call i32 @strlen(i8* %10)
%37 = add nsw i32 %36, 1
%38 = call i32 @memcpy(i8* %33, i8* %10, i32 %37)
br label %39
39: ; preds = %47, %35
%40 = phi i32 [ 1, %35 ], [ %54, %47 ]
%41 = phi i32 [ %37, %35 ], [ %53, %47 ]
store i32 0, i32* %6
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32* %6)
%46 = icmp slt i32 %45, 1
br i1 %46, label %63, label %47
47: ; preds = %39
%48 = call i32 @strlen(i8* %10)
%49 = add nsw i32 %48, 1
%50 = sext i32 %41 to i64
%51 = getelementptr inbounds i8, i8* %33, i64 %50
%52 = call i32 @memcpy(i8* %51, i8* %10, i32 %49)
%53 = add nsw i32 %49, %41
%54 = add nuw nsw i32 %40, 1
%55 = load i32, i32* %6
%56 = load i32, i32* %5
%57 = add nsw i32 %56, %55
store i32 %57, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %0, i64 %58
%60 = load i8, i8* %59
%61 = call i64 @isgraph(i8 signext %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %39
63: ; preds = %39, %47
%64 = phi i32 [ %54, %47 ], [ %40, %39 ]
%65 = phi i32 [ %53, %47 ], [ %41, %39 ]
br label %69
66: ; preds = %30
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %80
69: ; preds = %24, %21, %63
%70 = phi i8* [ %10, %24 ], [ %10, %21 ], [ %33, %63 ]
%71 = phi i32 [ 1, %24 ], [ 1, %21 ], [ %64, %63 ]
%72 = phi i32 [ 0, %24 ], [ 0, %21 ], [ %65, %63 ]
%73 = load i32, i32* %2
%74 = load i32, i32* %3
%75 = load i32, i32* %4
%76 = call i32 @cpio_mkfile(i8* %70, i8* %11, i32 %73, i32 %74, i32 %75, i32 %71)
%77 = icmp eq i32 %72, 0
br i1 %77, label %80, label %78
78: ; preds = %69
%79 = call i32 @free(i8* %70)
br label %80
80: ; preds = %66, %18, %69, %78
%81 = phi i32 [ %76, %69 ], [ %76, %78 ], [ -1, %18 ], [ -1, %66 ]
ret i32 %81
}