#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
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 *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char buffer[60];
  char *s;
  char *infile;
  FILE *fd;
  if (argc != 2) {
    fprintf(stderr, "usage: strcat <file>\n");
    exit(1);
  }
  infile = argv[1];
  fd = fopen(infile, "r");
  assert(fd != NULL);
  s = fgets(buffer, 60, fd);
  while (s != NULL) {
    printf("%s", s);
    s = fgets(buffer, 60, fd);
  }
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x3f>
mov    0x2e49(%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,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x3c,%esi
call   1050 <fgets@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     122d <main+0xbd>
mov    -0x58(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x3c,%esi
call   1050 <fgets@plt>
mov    %rax,-0x58(%rbp)
jmp    11f7 <main+0x87>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
cmp    $0x2,%edi
jne    11f4 <main+0x84>
mov    0x8(%rsi),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %rsp,%rdi
mov    $0x3c,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0x70>
lea    0xe5d(%rip),%r14
mov    %rsp,%r15
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x3c,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%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: strcat <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
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 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** %8
%20 = load i8*, i8** %8
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %9
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%27 = load i32*, i32** %9
%28 = call i8* @fgets(i8* %26, i32 60, i32* %27)
store i8* %28, i8** %7
br label %29
29: ; preds = %32, %16
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%36 = load i32*, i32** %9
%37 = call i8* @fgets(i8* %35, i32 60, i32* %36)
store i8* %37, i8** %7
br label %29
38: ; preds = %29
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: strcat <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [60 x i8]
%4 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%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 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32* %13, null
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = call i8* @fgets(i8* %4, i32 60, i32* %13)
%18 = icmp eq i8* %17, null
br i1 %18, label %24, label %19
19: ; preds = %10, %19
%20 = phi i8* [ %22, %19 ], [ %17, %10 ]
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i8* @fgets(i8* %4, i32 60, i32* %13)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %19
24: ; preds = %19, %10
%25 = call i32 @fclose(i32* %13)
ret i32 0
}