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

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int write(int, int *, int);
int main(int argc, char *argv[]) {
  char buffer[60];
  char *s;
  char *infile;
  char *outfile;
  int value;
  FILE *fd;
  int ofd;
  if (argc != 3) {
    fprintf(stderr, "usage: strrev <infile> <outfile>\n");
    exit(1);
  }
  infile = argv[1];
  outfile = argv[2];
  fd = fopen(infile, "r");
  ofd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
  assert(fd != NULL);
  assert(ofd > -1);
  s = fgets(buffer, 60, fd);
  while (s != NULL) {
    if (s[0] == '-') {
      int i;
      int j;
      j = 0;
      char *newString = (char *)malloc(strlen(s) - 2 * sizeof(char));
      for (i = 2; i < strlen(s); i++) {
        newString[j] = s[i];
        j++;
      }
      value = (atoi(newString) * -1);
    } else {
      value = atoi(s);
    }
    int rc = write(ofd, &value, sizeof(int));
    assert(rc == sizeof(int));
    s = fgets(buffer, 60, fd);
  }
  close(ofd);
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1202 <main+0x42>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x68(%rbp),%rdi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
mov    0x2db6(%rip),%rax
or     (%rax),%esi
mov    0x2da5(%rip),%rax
or     (%rax),%esi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
call   10b0 <open@plt>
mov    %eax,-0x7c(%rbp)
cmpq   $0x0,-0x78(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0xffffffff,-0x7c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x3c,%esi
call   1070 <fgets@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     13a8 <main+0x1e8>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1352 <main+0x192>
movl   $0x0,-0x84(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <strlen@plt>
cltq
sub    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x90(%rbp)
movl   $0x2,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    %eax,-0x98(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%eax
cmp    %ecx,%eax
jge    133b <main+0x17b>
mov    -0x58(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x90(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    12e0 <main+0x120>
mov    -0x90(%rbp),%rdi
call   10d0 <atoi@plt>
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x6c(%rbp)
jmp    135e <main+0x19e>
mov    -0x58(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x7c(%rbp),%edi
lea    -0x6c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x94(%rbp)
movslq -0x94(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x3c,%esi
call   1070 <fgets@plt>
mov    %rax,-0x58(%rbp)
jmp    1297 <main+0xd7>
mov    -0x7c(%rbp),%edi
call   1060 <close@plt>
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
cmp    $0x3,%edi
jne    1335 <main+0x175>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbx
lea    0xe3c(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
mov    0x2dc3(%rip),%rax
mov    0x2dfc(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,%r12d
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1080 <assert@plt>
mov    %r12d,%edi
not    %edi
shr    $0x1f,%edi
call   1080 <assert@plt>
lea    0x10(%rsp),%rdi
mov    $0x3c,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1314 <main+0x154>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%rbp
mov    %r12d,0x8(%rsp)
jmp    12b2 <main+0xf2>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10d0 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
mov    %rbp,%rdi
mov    $0x3c,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1314 <main+0x154>
cmpb   $0x2d,(%rbx)
jne    1270 <main+0xb0>
mov    %rbp,%r12
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    -0x2(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x3,%eax
jl     12fd <main+0x13d>
mov    $0x2,%r14d
movzbl (%rbx,%r14,1),%eax
mov    %al,-0x2(%rbp,%r14,1)
add    $0x1,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%r14
jl     12e0 <main+0x120>
mov    %rbp,%rdi
call   10d0 <atoi@plt>
neg    %eax
mov    %r12,%rbp
mov    0x8(%rsp),%r12d
jmp    1278 <main+0xb8>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
lea    0xcbb(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"usage: strrev <infile> <outfile>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [60 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %9
%30 = load i8*, i8** %8
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %11
%32 = load i8*, i8** %9
%33 = load i32, i32* @O_WRONLY
%34 = load i32, i32* @O_CREAT
%35 = or i32 %33, %34
%36 = load i32, i32* @O_TRUNC
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IRWXU
%39 = call i32 @open(i8* %32, i32 %37, i32 %38)
store i32 %39, i32* %12
%40 = load i32*, i32** %11
%41 = icmp ne i32* %40, null
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* %12
%45 = icmp sgt i32 %44, -1
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%49 = load i32*, i32** %11
%50 = call i8* @fgets(i8* %48, i32 60, i32* %49)
store i8* %50, i8** %7
br label %51
51: ; preds = %95, %23
%52 = load i8*, i8** %7
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %106
54: ; preds = %51
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i64 0
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 45
br i1 %59, label %60, label %92
60: ; preds = %54
store i32 0, i32* %14
%61 = load i8*, i8** %7
%62 = call i32 @strlen(i8* %61)
%63 = sext i32 %62 to i64
%64 = sub i64 %63, 2
%65 = trunc i64 %64 to i32
%66 = call i64 @malloc(i32 %65)
%67 = inttoptr i64 %66 to i8*
store i8* %67, i8** %15
store i32 2, i32* %13
br label %68
68: ; preds = %85, %60
%69 = load i32, i32* %13
%70 = load i8*, i8** %7
%71 = call i32 @strlen(i8* %70)
%72 = icmp slt i32 %69, %71
br i1 %72, label %73, label %88
73: ; preds = %68
%74 = load i8*, i8** %7
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
%78 = load i8, i8* %77
%79 = load i8*, i8** %15
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
store i8 %78, i8* %82
%83 = load i32, i32* %14
%84 = add nsw i32 %83, 1
store i32 %84, i32* %14
br label %85
85: ; preds = %73
%86 = load i32, i32* %13
%87 = add nsw i32 %86, 1
store i32 %87, i32* %13
br label %68
88: ; preds = %68
%89 = load i8*, i8** %15
%90 = call i32 @atoi(i8* %89)
%91 = mul nsw i32 %90, -1
store i32 %91, i32* %10
br label %95
92: ; preds = %54
%93 = load i8*, i8** %7
%94 = call i32 @atoi(i8* %93)
store i32 %94, i32* %10
br label %95
95: ; preds = %92, %88
%96 = load i32, i32* %12
%97 = call i32 @write(i32 %96, i32* %10, i32 4)
store i32 %97, i32* %16
%98 = load i32, i32* %16
%99 = sext i32 %98 to i64
%100 = icmp eq i64 %99, 4
%101 = zext i1 %100 to i32
%102 = call i32 @assert(i32 %101)
%103 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%104 = load i32*, i32** %11
%105 = call i8* @fgets(i8* %103, i32 60, i32* %104)
store i8* %105, i8** %7
br label %51
106: ; preds = %51
%107 = load i32, i32* %12
%108 = call i32 @close(i32 %107)
%109 = load i32*, i32** %11
%110 = call i32 @fclose(i32* %109)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"usage: strrev <infile> <outfile>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [60 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @O_WRONLY
%19 = load i32, i32* @O_CREAT
%20 = or i32 %19, %18
%21 = load i32, i32* @O_TRUNC
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRWXU
%24 = tail call i32 @open(i8* %16, i32 %22, i32 %23)
%25 = icmp ne i32* %17, null
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = xor i32 %24, -1
%29 = lshr i32 %28, 31
%30 = tail call i32 @assert(i32 %29)
%31 = call i8* @fgets(i8* %5, i32 60, i32* %17)
%32 = icmp eq i8* %31, null
br i1 %32, label %68, label %33
33: ; preds = %12, %60
%34 = phi i8* [ %66, %60 ], [ %31, %12 ]
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 45
br i1 %36, label %37, label %58
37: ; preds = %33
%38 = call i32 @strlen(i8* %34)
%39 = add i32 %38, -2
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
%42 = call i32 @strlen(i8* %34)
%43 = icmp sgt i32 %42, 2
br i1 %43, label %44, label %55
44: ; preds = %37, %44
%45 = phi i64 [ %50, %44 ], [ 0, %37 ]
%46 = phi i64 [ %51, %44 ], [ 2, %37 ]
%47 = getelementptr inbounds i8, i8* %34, i64 %46
%48 = load i8, i8* %47
%49 = getelementptr inbounds i8, i8* %41, i64 %45
store i8 %48, i8* %49
%50 = add nuw nsw i64 %45, 1
%51 = add nuw nsw i64 %46, 1
%52 = call i32 @strlen(i8* %34)
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %44, label %55
55: ; preds = %44, %37
%56 = call i32 @atoi(i8* %41)
%57 = sub nsw i32 0, %56
br label %60
58: ; preds = %33
%59 = call i32 @atoi(i8* %34)
br label %60
60: ; preds = %58, %55
%61 = phi i32 [ %59, %58 ], [ %57, %55 ]
store i32 %61, i32* %4
%62 = call i32 @write(i32 %24, i32* %4, i32 4)
%63 = icmp eq i32 %62, 4
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = call i8* @fgets(i8* %5, i32 60, i32* %17)
%67 = icmp eq i8* %66, null
br i1 %67, label %68, label %33
68: ; preds = %60, %12
%69 = call i32 @close(i32 %24)
%70 = call i32 @fclose(i32* %17)
ret i32 0
}