#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 */
struct minijail {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ minijail_bind(struct minijail *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strtok(char *, char *);
void add_binding(struct minijail *j, char *arg) {
  char *src = strtok(arg, ",");
  char *dest = strtok(NULL, ",");
  char *flags = strtok(NULL, ",");
  if (!src || !dest) {
    fprintf(stderr, "Bad binding: %s %s\n", src, dest);
    exit(1);
  }
  if (minijail_bind(j, src, dest, flags ? atoi(flags) : 0)) {
    fprintf(stderr, "Bind failure.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<add_binding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe81(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe6d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b2 <add_binding+0x62>
cmpq   $0x0,-0x20(%rbp)
jne    11db <add_binding+0x8b>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120f <add_binding+0xbf>
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x44(%rbp)
jmp    1219 <add_binding+0xc9>
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
jmp    1219 <add_binding+0xc9>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%ecx
call   1030 <minijail_bind@plt>
cmp    $0x0,%rax
je     1258 <add_binding+0x108>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_binding>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe9e(%rip),%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
test   %r15,%r15
je     11c3 <add_binding+0x73>
test   %r12,%r12
je     11c3 <add_binding+0x73>
test   %rax,%rax
je     11a2 <add_binding+0x52>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
jmp    11a4 <add_binding+0x54>
xor    %ecx,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <minijail_bind@plt>
test   %rax,%rax
jne    11ea <add_binding+0x9a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.minijail = type { i32 }
@.str = [2 x i8] c",\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Bad binding: %s %s\0A\00"
@.str.2 = [15 x i8] c"Bind failure.\0A\00"
define void @add_binding(%struct.minijail* %0, i8* %1) {
%3 = alloca %struct.minijail*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store %struct.minijail* %0, %struct.minijail** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
%11 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %7
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %23, label %17
17: ; preds = %14, %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = load %struct.minijail*, %struct.minijail** %3
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = call i32 @atoi(i8* %30)
br label %33
32: ; preds = %23
br label %33
33: ; preds = %32, %29
%34 = phi i32 [ %31, %29 ], [ 0, %32 ]
%35 = call i64 @minijail_bind(%struct.minijail* %24, i8* %25, i8* %26, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
ret void
}

LLVM IR (-O2):
%struct.minijail = type { i32 }
@.str = [2 x i8] c",\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Bad binding: %s %s\0A\00"
@.str.2 = [15 x i8] c"Bind failure.\0A\00"
define void @add_binding(%struct.minijail* %0, i8* %1) {
%3 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i8* %3, null
%7 = icmp ne i8* %4, null
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = icmp eq i8* %5, null
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = tail call i32 @atoi(i8* %5)
br label %17
17: ; preds = %13, %15
%18 = phi i32 [ %16, %15 ], [ 0, %13 ]
%19 = tail call i64 @minijail_bind(%struct.minijail* %0, i8* %3, i8* %4, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
ret void
}