#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int main() {
  FILE *fp;
  char str[102] = {0}, strTemp[100];
  if ((fp = fopen("/home/gerry/ssh3", "at+")) == NULL) {
    printf("Cannot open file, press any key to exit!\n");
    getchar();
    exit(1);
  }
  printf("Input a string:");
  fgets(strTemp, 100, stdin);
  strcat(str, "\n");
  strcat(str, strTemp);
  fputs(str, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x66,%edx
call   1060 <memset@plt>
lea    0xe47(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f0 <main+0x60>
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fgets@plt>
lea    -0x80(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x80(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x5e(%rsp)
lea    0xe34(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1246 <main+0xb6>
mov    %rax,%rbx
lea    0xe2e(%rip),%rdi
call   1050 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
lea    0x70(%rsp),%r14
mov    %r14,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
lea    0xe17(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   10a0 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdda(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/home/gerry/ssh3\00"
@.str.1 = [4 x i8] c"at+\00"
@.str.2 = [42 x i8] c"Cannot open file, press any key to exit!\0A\00"
@.str.3 = [16 x i8] c"Input a string:\00"
@stdin = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [102 x i8]
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = bitcast [102 x i8]* %3 to i8*
%6 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (...) @getchar()
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 100, i32 %15)
%17 = getelementptr inbounds [102 x i8], [102 x i8]* %3, i64 0, i64 0
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = getelementptr inbounds [102 x i8], [102 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = getelementptr inbounds [102 x i8], [102 x i8]* %3, i64 0, i64 0
%23 = load i32*, i32** %2
%24 = call i32 @fputs(i8* %22, i32* %23)
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"/home/gerry/ssh3\00"
@.str.1 = [4 x i8] c"at+\00"
@.str.3 = [16 x i8] c"Input a string:\00"
@stdin = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@str = [41 x i8] c"Cannot open file, press any key to exit!\00"
define i32 @main() {
%1 = alloca [102 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [102 x i8], [102 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (...) @getchar()
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %4, i32 100, i32 %13)
%15 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @strcat(i8* %3, i8* %4)
%17 = call i32 @fputs(i8* %3, i32* %5)
%18 = call i32 @fclose(i32* %5)
ret i32 0
}