#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*/ bin2hex(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ hex2hex(char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
void rebuild_file(char *line) {
  char *method, *next, *old, *var, *p;
  method = p = line;
  while (*p && *p != ' ')
    p++;
  *p++ = 0;
  old = p;
  while (*p && *p != ' ')
    p++;
  *p++ = 0;
  next = p;
  while (*p && *p != ' ')
    p++;
  *p++ = 0;
  var = p;
  while (*p && *p != ' ')
    p++;
  *p++ = 0;
  fprintf(stderr, "Rebuilding file `%s' (%s %s)\n", next, method, old);
  if (strcmp(method, "bin2hex") == 0) {
    if (!bin2hex(old, next, var)) {
      fprintf(stderr, "Rebuild failed\n");
      exit(-1);
    }
  } else if (strcmp(method, "hex2hex") == 0) {
    if (!hex2hex(old, next, var)) {
      fprintf(stderr, "Rebuild failed\n");
      exit(-1);
    }
  } else {
    fprintf(stderr, "Failed to build `%s' - unknown method %s\n", next, method);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<rebuild_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     118d <rebuild_file+0x3d>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    119d <rebuild_file+0x4d>
jmp    11ae <rebuild_file+0x5e>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1168 <rebuild_file+0x18>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x32(%rbp)
je     11ed <rebuild_file+0x9d>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    11fd <rebuild_file+0xad>
jmp    120e <rebuild_file+0xbe>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11c8 <rebuild_file+0x78>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x33(%rbp)
je     124d <rebuild_file+0xfd>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x33(%rbp)
mov    -0x33(%rbp),%al
test   $0x1,%al
jne    125d <rebuild_file+0x10d>
jmp    126e <rebuild_file+0x11e>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1228 <rebuild_file+0xd8>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x34(%rbp)
je     12ad <rebuild_file+0x15d>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x34(%rbp)
mov    -0x34(%rbp),%al
test   $0x1,%al
jne    12bd <rebuild_file+0x16d>
jmp    12ce <rebuild_file+0x17e>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1288 <rebuild_file+0x138>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xd04(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd10(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    135d <rebuild_file+0x20d>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <bin2hex@plt>
cmp    $0x0,%eax
jne    1358 <rebuild_file+0x208>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xcdf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    13e5 <rebuild_file+0x295>
mov    -0x10(%rbp),%rdi
lea    0xcce(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    13b7 <rebuild_file+0x267>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <hex2hex@plt>
cmp    $0x0,%eax
jne    13b2 <rebuild_file+0x262>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
lea    0xc85(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    13e0 <rebuild_file+0x290>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xc6f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    13e5 <rebuild_file+0x295>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rebuild_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0x1(%rdi),%r15
testb  $0xdf,-0x1(%r15)
je     117b <rebuild_file+0x2b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
testb  $0xdf,-0x1(%r15)
jne    1170 <rebuild_file+0x20>
movb   $0x0,-0x1(%r15)
lea    0x2(%r15),%rbx
testb  $0xdf,-0x2(%rbx)
je     119a <rebuild_file+0x4a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
testb  $0xdf,-0x2(%rbx)
jne    1190 <rebuild_file+0x40>
lea    -0x1(%rbx),%r12
movb   $0x0,-0x2(%rbx)
testb  $0xdf,-0x1(%rbx)
je     11ba <rebuild_file+0x6a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
testb  $0xdf,-0x1(%rbx)
jne    11b0 <rebuild_file+0x60>
movb   $0x0,-0x1(%rbx)
mov    %rbx,%rax
testb  $0xdf,(%rax)
je     11d9 <rebuild_file+0x89>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rax
testb  $0xdf,(%rax)
jne    11d0 <rebuild_file+0x80>
movb   $0x0,(%rax)
mov    0x2dfd(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe12(%rip),%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe19(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1242 <rebuild_file+0xf2>
lea    0xe1d(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1270 <rebuild_file+0x120>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <hex2hex@plt>
test   %eax,%eax
je     1254 <rebuild_file+0x104>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <bin2hex@plt>
test   %eax,%eax
jne    1238 <rebuild_file+0xe8>
mov    0x0(%r13),%edi
lea    0xdc7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x0(%r13),%edi
lea    0xdc3(%rip),%rsi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Rebuilding file `%s' (%s %s)\0A\00"
@.str.1 = [8 x i8] c"bin2hex\00"
@.str.2 = [16 x i8] c"Rebuild failed\0A\00"
@.str.3 = [8 x i8] c"hex2hex\00"
@.str.4 = [42 x i8] c"Failed to build `%s' - unknown method %s\0A\00"
define void @rebuild_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
store i8* %8, i8** %7
store i8* %8, i8** %3
br label %9
9: ; preds = %21, %1
%10 = load i8*, i8** %7
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 32
br label %19
19: ; preds = %14, %9
%20 = phi i1 [ false, %9 ], [ %18, %14 ]
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %7
br label %9
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
store i8 0, i8* %25
%27 = load i8*, i8** %7
store i8* %27, i8** %5
br label %28
28: ; preds = %40, %24
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i8*, i8** %7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 32
br label %38
38: ; preds = %33, %28
%39 = phi i1 [ false, %28 ], [ %37, %33 ]
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %7
br label %28
43: ; preds = %38
%44 = load i8*, i8** %7
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %7
store i8 0, i8* %44
%46 = load i8*, i8** %7
store i8* %46, i8** %4
br label %47
47: ; preds = %59, %43
%48 = load i8*, i8** %7
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %47
%53 = load i8*, i8** %7
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 32
br label %57
57: ; preds = %52, %47
%58 = phi i1 [ false, %47 ], [ %56, %52 ]
br i1 %58, label %59, label %62
59: ; preds = %57
%60 = load i8*, i8** %7
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %7
br label %47
62: ; preds = %57
%63 = load i8*, i8** %7
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %7
store i8 0, i8* %63
%65 = load i8*, i8** %7
store i8* %65, i8** %6
br label %66
66: ; preds = %78, %62
%67 = load i8*, i8** %7
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load i8*, i8** %7
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 32
br label %76
76: ; preds = %71, %66
%77 = phi i1 [ false, %66 ], [ %75, %71 ]
br i1 %77, label %78, label %81
78: ; preds = %76
%79 = load i8*, i8** %7
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %7
br label %66
81: ; preds = %76
%82 = load i8*, i8** %7
%83 = getelementptr inbounds i8, i8* %82, i32 1
store i8* %83, i8** %7
store i8 0, i8* %82
%84 = load i32, i32* @stderr
%85 = load i8*, i8** %4
%86 = load i8*, i8** %3
%87 = load i8*, i8** %5
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %85, i8* %86, i8* %87)
%89 = load i8*, i8** %3
%90 = call i64 @strcmp(i8* %89, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %103
92: ; preds = %81
%93 = load i8*, i8** %5
%94 = load i8*, i8** %4
%95 = load i8*, i8** %6
%96 = call i32 @bin2hex(i8* %93, i8* %94, i8* %95)
%97 = icmp ne i32 %96, 0
br i1 %97, label %102, label %98
98: ; preds = %92
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%101 = call i32 @exit(i32 -1)
unreachable
102: ; preds = %92
br label %125
103: ; preds = %81
%104 = load i8*, i8** %3
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %118
107: ; preds = %103
%108 = load i8*, i8** %5
%109 = load i8*, i8** %4
%110 = load i8*, i8** %6
%111 = call i32 @hex2hex(i8* %108, i8* %109, i8* %110)
%112 = icmp ne i32 %111, 0
br i1 %112, label %117, label %113
113: ; preds = %107
%114 = load i32, i32* @stderr
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%116 = call i32 @exit(i32 -1)
unreachable
117: ; preds = %107
br label %124
118: ; preds = %103
%119 = load i32, i32* @stderr
%120 = load i8*, i8** %4
%121 = load i8*, i8** %3
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %120, i8* %121)
%123 = call i32 @exit(i32 -1)
unreachable
124: ; preds = %117
br label %125
125: ; preds = %124, %102
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Rebuilding file `%s' (%s %s)\0A\00"
@.str.1 = [8 x i8] c"bin2hex\00"
@.str.2 = [16 x i8] c"Rebuild failed\0A\00"
@.str.3 = [8 x i8] c"hex2hex\00"
@.str.4 = [42 x i8] c"Failed to build `%s' - unknown method %s\0A\00"
define void @rebuild_file(i8* %0) {
br label %2
2: ; preds = %5, %1
%3 = phi i8* [ %0, %1 ], [ %6, %5 ]
%4 = load i8, i8* %3
switch i8 %4, label %5 [
i8 0, label %7
i8 32, label %7
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
7: ; preds = %2, %2
%8 = getelementptr inbounds i8, i8* %3, i64 1
store i8 0, i8* %3
br label %9
9: ; preds = %12, %7
%10 = phi i8* [ %8, %7 ], [ %13, %12 ]
%11 = load i8, i8* %10
switch i8 %11, label %12 [
i8 0, label %14
i8 32, label %14
]
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
14: ; preds = %9, %9
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8 0, i8* %10
br label %16
16: ; preds = %19, %14
%17 = phi i8* [ %15, %14 ], [ %20, %19 ]
%18 = load i8, i8* %17
switch i8 %18, label %19 [
i8 0, label %21
i8 32, label %21
]
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %17, i64 1
br label %16
21: ; preds = %16, %16
%22 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %17
br label %23
23: ; preds = %26, %21
%24 = phi i8* [ %22, %21 ], [ %27, %26 ]
%25 = load i8, i8* %24
switch i8 %25, label %26 [
i8 0, label %28
i8 32, label %28
]
26: ; preds = %23
%27 = getelementptr inbounds i8, i8* %24, i64 1
br label %23
28: ; preds = %23, %23
store i8 0, i8* %24
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %0, i8* %8)
%31 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = tail call i32 @bin2hex(i8* %8, i8* %15, i8* %22)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %54
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%39 = tail call i32 @exit(i32 -1)
unreachable
40: ; preds = %28
%41 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = tail call i32 @hex2hex(i8* %8, i8* %15, i8* %22)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%49 = tail call i32 @exit(i32 -1)
unreachable
50: ; preds = %40
%51 = load i32, i32* @stderr
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %15, i8* %0)
%53 = tail call i32 @exit(i32 -1)
unreachable
54: ; preds = %43, %33
ret void
}