#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int create_shell_file() {
  FILE *fp = NULL;
  char contents[256] = {0};
  strcpy(contents, "#! /bin/sh\n"
                   "nvram set $2=\"$1\"\n"
                   "nvram commit");
  if ((fp = fopen("/tmp/smartsync/usbclient/script/write_nvram", "w")) ==
      NULL) {
    fprintf(stderr, "create shell file error");
    return -1;
  }
  fprintf(fp, "%s", contents);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<create_shell_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movq   $0x0,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x110(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe9a(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ce <create_shell_file+0x7e>
mov    0x2e2f(%rip),%rax
movslq (%rax),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <create_shell_file+0xa7>
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_shell_file>:
push   %rbx
sub    $0x100,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe37(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0xe52(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1203 <create_shell_file+0xb3>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1228 <create_shell_file+0xd8>
mov    0x2dd6(%rip),%rax
movslq (%rax),%rcx
lea    0xe44(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"#! /bin/sh\0Anvram set $2=\22$1\22\0Anvram commit\00"
@.str.1 = [44 x i8] c"/tmp/smartsync/usbclient/script/write_nvram\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [24 x i8] c"create shell file error\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @create_shell_file() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
store i32* null, i32** %2
%4 = bitcast [256 x i8]* %3 to i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %7, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %20
14: ; preds = %0
%15 = load i32*, i32** %2
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %1
br label %20
20: ; preds = %14, %9
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [42 x i8] c"#! /bin/sh\0Anvram set $2=\22$1\22\0Anvram commit\00"
@.str.1 = [44 x i8] c"/tmp/smartsync/usbclient/script/write_nvram\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [24 x i8] c"create shell file error\00"
define i32 @create_shell_file() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%4 = call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 23, i64 1, i32* %9)
br label %14
11: ; preds = %0
%12 = call i32 @fputs(i8* %2, i32* %4)
%13 = call i32 @fclose(i32* %4)
br label %14
14: ; preds = %11, %6
%15 = phi i32 [ -1, %6 ], [ 0, %11 ]
ret i32 %15
}