#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void writeClientIp(char *ip) {
  char filename[1024] = "";
  strcat(filename, "./control/");
  strcat(filename, "client_ip");
  FILE *file;
  if ((file = fopen(filename, "w")) == NULL) {
    perror("Cannot open file.");
    exit(1);
  }
  fprintf(file, "%s", ip);
  printf("\n%s\n", ip);
  fclose(file);
}


x86 assembly (clang, -O0):
<writeClientIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
jne    1202 <writeClientIp+0x82>
lea    0xe24(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x418(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe15(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeClientIp>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe56(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1201 <writeClientIp+0x81>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
lea    0xe43(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"./control/\00"
@.str.1 = [10 x i8] c"client_ip\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [18 x i8] c"Cannot open file.\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"\0A%s\0A\00"
define void @writeClientIp(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = bitcast [1024 x i8]* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i32*, i32** %4
%18 = load i8*, i8** %2
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %2
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"./control/\00"
@.str.1 = [10 x i8] c"client_ip\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [18 x i8] c"Cannot open file.\00"
@.str.5 = [5 x i8] c"\0A%s\0A\00"
define void @writeClientIp(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = call i32 @fputs(i8* %0, i32* %6)
%13 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%14 = call i32 @fclose(i32* %6)
ret void
}