#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  size_t count;
  if (argc < 1) {
    fprintf(stderr, "Usage: %s <infile> \n", argv[0]);
    return 1;
  }
  FILE *in;
  if ((in = fopen(argv[1], "rb")) == NULL) {
    perror("could not open input file");
    return 1;
  }
  printf("chgme   ");
  count = 0;
  while (1) {
    uint8_t c = fgetc(in);
    if (feof(in))
      break;
    if (!(count % 8)) {
      if (count)
        printf("\n        ");
      printf(".byt  $%02x", c);
    } else {
      printf(", $%02x", c);
    }
    count++;
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    11b8 <main+0x48>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129f <main+0x12f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f2 <main+0x82>
lea    0xe37(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    129f <main+0x12f>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     122c <main+0xbc>
jmp    128f <main+0x11f>
mov    -0x18(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    126d <main+0xfd>
cmpq   $0x0,-0x18(%rbp)
je     1257 <main+0xe7>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127e <main+0x10e>
mov    -0x24(%rbp),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1208 <main+0x98>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11cd <main+0x5d>
mov    0x8(%rsi),%rdi
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1258 <main+0xe8>
mov    %rax,%rbx
lea    0xe90(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11fd <main+0x8d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11eb <main+0x7b>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe20(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4d(%rip),%r12
lea    0xe3a(%rip),%r13
xor    %r15d,%r15d
jmp    1234 <main+0xc4>
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11c3 <main+0x53>
mov    %r12,%rdi
test   $0x7,%r15b
jne    1210 <main+0xa0>
mov    %r13,%rdi
test   %r15,%r15
je     1210 <main+0xa0>
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
jmp    1210 <main+0xa0>
lea    0xdb9(%rip),%rdi
call   1090 <perror@plt>
jmp    11e5 <main+0x75>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s <infile> \0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [26 x i8] c"could not open input file\00"
@.str.3 = [9 x i8] c"chgme \00"
@.str.4 = [10 x i8] c"\0A \00"
@.str.5 = [12 x i8] c".byt $%02x\00"
@.str.6 = [8 x i8] c", $%02x\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %55
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %55
25: ; preds = %17
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %6
br label %27
27: ; preds = %25, %49
%28 = load i32*, i32** %7
%29 = call i32 @fgetc(i32* %28)
store i32 %29, i32* %8
%30 = load i32*, i32** %7
%31 = call i64 @feof(i32* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
br label %52
34: ; preds = %27
%35 = load i64, i64* %6
%36 = urem i64 %35, 8
%37 = icmp ne i64 %36, 0
br i1 %37, label %46, label %38
38: ; preds = %34
%39 = load i64, i64* %6
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = load i32, i32* %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %44)
br label %49
46: ; preds = %34
%47 = load i32, i32* %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46, %43
%50 = load i64, i64* %6
%51 = add i64 %50, 1
store i64 %51, i64* %6
br label %27
52: ; preds = %33
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %52, %23, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s <infile> \0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [26 x i8] c"could not open input file\00"
@.str.3 = [9 x i8] c"chgme \00"
@.str.4 = [10 x i8] c"\0A \00"
@.str.5 = [12 x i8] c".byt $%02x\00"
@.str.6 = [8 x i8] c", $%02x\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %38
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %38
15: ; preds = %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 @fgetc(i32* %11)
%18 = tail call i64 @feof(i32* %11)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %15, %29
%21 = phi i32 [ %33, %29 ], [ %17, %15 ]
%22 = phi i64 [ %32, %29 ], [ 0, %15 ]
%23 = and i64 %22, 7
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = icmp eq i64 %22, 0
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %20, %25, %27
%30 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), %27 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), %25 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %20 ]
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %30, i32 %21)
%32 = add i64 %22, 1
%33 = tail call i32 @fgetc(i32* %11)
%34 = tail call i64 @feof(i32* %11)
%35 = icmp eq i64 %34, 0
br i1 %35, label %20, label %36
36: ; preds = %29, %15
%37 = tail call i32 @fclose(i32* %11)
br label %38
38: ; preds = %13, %36, %4
%39 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 0, %36 ]
ret i32 %39
}