#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*/ O_RDONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, int *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *infile;
  int fd;
  int count;
  int buf;
  if (argc != 2) {
    fprintf(stderr, "usage: intcat <file>\n");
    exit(1);
  }
  infile = argv[1];
  fd = open(infile, O_RDONLY);
  assert(fd > -1);
  count = read(fd, &buf, 4);
  while (count == 4) {
    if (buf < 0) {
      buf *= -1;
      printf("- %d\n", buf);
    } else {
      printf("%d\n", buf);
    }
    count = read(fd, &buf, 4);
  }
  close(fd);
  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   $0x2,-0x8(%rbp)
je     11af <main+0x3f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jne    124c <main+0xdc>
cmpl   $0x0,-0x24(%rbp)
jge    1224 <main+0xb4>
imul   $0xffffffff,-0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
jmp    1233 <main+0xc3>
mov    -0x24(%rbp),%esi
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
jmp    11f5 <main+0x85>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1214 <main+0xa4>
mov    0x8(%rsi),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1060 <assert@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11ff <main+0x8f>
lea    0xe58(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe4e(%rip),%r12
jmp    11ec <main+0x7c>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11ff <main+0x8f>
mov    0x4(%rsp),%esi
test   %esi,%esi
jns    11d0 <main+0x60>
neg    %esi
mov    %esi,0x4(%rsp)
mov    %r14,%rdi
jmp    11d3 <main+0x63>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"usage: intcat <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"- %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, -1
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %7
%28 = call i32 @read(i32 %27, i32* %9, i32 4)
store i32 %28, i32* %8
br label %29
29: ; preds = %43, %16
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 4
br i1 %31, label %32, label %46
32: ; preds = %29
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* %9
%37 = mul nsw i32 %36, -1
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %43
40: ; preds = %32
%41 = load i32, i32* %9
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40, %35
%44 = load i32, i32* %7
%45 = call i32 @read(i32 %44, i32* %9, i32 4)
store i32 %45, i32* %8
br label %29
46: ; preds = %29
%47 = load i32, i32* %7
%48 = call i32 @close(i32 %47)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: intcat <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"- %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = xor i32 %14, -1
%16 = lshr i32 %15, 31
%17 = tail call i32 @assert(i32 %16)
%18 = call i32 @read(i32 %14, i32* %3, i32 4)
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %31
20: ; preds = %10, %28
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = sub nsw i32 0, %21
store i32 %24, i32* %3
%25 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %20
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %28
28: ; preds = %26, %23
%29 = call i32 @read(i32 %14, i32* %3, i32 4)
%30 = icmp eq i32 %29, 4
br i1 %30, label %20, label %31
31: ; preds = %28, %10
%32 = tail call i32 @close(i32 %14)
ret i32 0
}