#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 atol(char *);
int ncat(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
int main(int argc, char **argv) {
  char *s = argc > 2 ? argv[1] : argv[0];
  char *t = argc > 3 ? argv[2] : "hello";
  int n = argc < 2 ? 5 : atol(argv[3]);
  int res = ncat(s, t, n);
  printf("%s res=%d\n", s, res);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1161 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    116c <main+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    118f <main+0x5f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    119f <main+0x6f>
lea    0xe6a(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    119f <main+0x6f>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11be <main+0x8e>
mov    $0x5,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ce <main+0x9e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atol@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <ncat@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
cmp    $0x3,%edi
setge  %al
mov    (%rsi,%rax,8),%rbx
jle    1148 <main+0x18>
mov    0x10(%rsi),%r14
jmp    1159 <main+0x29>
mov    $0x5,%edx
lea    0xeac(%rip),%r14
cmp    $0x2,%edi
jl     1164 <main+0x34>
mov    0x18(%rsi),%rdi
call   1040 <atol@plt>
mov    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <ncat@plt>
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@.str.1 = [11 x i8] c"%s res=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%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 sgt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
br label %20
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
br label %20
20: ; preds = %16, %12
%21 = phi i8* [ %15, %12 ], [ %19, %16 ]
store i8* %21, i8** %6
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 3
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
br label %29
28: ; preds = %20
br label %29
29: ; preds = %28, %24
%30 = phi i8* [ %27, %24 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %28 ]
store i8* %30, i8** %7
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 2
br i1 %32, label %33, label %34
33: ; preds = %29
br label %39
34: ; preds = %29
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @atol(i8* %37)
br label %39
39: ; preds = %34, %33
%40 = phi i32 [ 5, %33 ], [ %38, %34 ]
store i32 %40, i32* %8
%41 = load i8*, i8** %6
%42 = load i8*, i8** %7
%43 = load i32, i32* %8
%44 = call i32 @ncat(i8* %41, i8* %42, i32 %43)
store i32 %44, i32* %9
%45 = load i8*, i8** %6
%46 = load i32, i32* %9
%47 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %45, i32 %46)
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [11 x i8] c"%s res=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
%4 = zext i1 %3 to i64
%5 = getelementptr i8*, i8** %1, i64 %4
%6 = load i8*, i8** %5
%7 = icmp sgt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
br label %13
11: ; preds = %2
%12 = icmp slt i32 %0, 2
br i1 %12, label %18, label %13
13: ; preds = %8, %11
%14 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %11 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 @atol(i8* %16)
br label %18
18: ; preds = %11, %13
%19 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %11 ]
%20 = phi i32 [ %17, %13 ], [ 5, %11 ]
%21 = tail call i32 @ncat(i8* %6, i8* %19, i32 %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %21)
ret i32 0
}